Hadi Sharifi
Hadi Sharifi

Reputation: 1527

How can the data in the DataGrid be populated asynchronously in a streaming fashion?

In a Windows C# application form I load more than 500,000 records from a SQL Server database for analysis.

SELECT TOP 500000 * FROM MobileTrans

When I run above query in SQL Server Management Studio data shows up immediately and takes 15 sec to load be completed. But when I run this query in my Windows application, it takes 15 sec without showing anything in the data grid, after that data show in data grid suddenly.

How can I retrieve results of query async same as SQL Server Management Studio in my windows data grid form?

Please send a small sample of code.

Upvotes: 0

Views: 304

Answers (1)

Tigran
Tigran

Reputation: 62276

You do not need to show 1mln records to anyone. None can see them all contemporary. So first load reasonable amount of data one could see and operate in your app.

In short: use server side paging of the data if this is only about presentation.

By reducing in this way dramatically amount of data, you may avoid async processing at all.

If you need, by the way, process it in async I would go for populating data retrieved from DB into storage (Queue<T>, List<T>....) which is a source for visual element you visualize data on.

Consider that this can easily jump into fairly complicated scenarios, as it's not absolutely clear to me how complex your app is. So, may be the first solution would reveal as the best one.

EDIT

Here, may be, a useful example about how can be that (defered loading) achieved.

Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control

Upvotes: 5

Related Questions