Asynchronously populate datagridview in Windows Forms application

Posted by dcryptd on Stack Overflow See other posts from Stack Overflow or by dcryptd
Published on 2009-08-31T13:26:01Z Indexed on 2010/05/04 1:28 UTC
Read the original article Hit count: 464

howzit!

I'm a web developer that has been recently requested to develop a Windows forms application, so please bear with me (or dont laugh!) if my question is a bit elementary.

After many sessions with my client, we eventually decided on an interface that contains a tabcontrol with 5 tabs. Each tab has a datagridview that may eventually hold up to 25,000 rows of data (with about 6 columns each). I have successfully managed to bind the grids when the tab page is loaded and it works fine for a few records, but the UI freezes when I bound the grid with 20,000 dummy records. The "freeze" occurs when I click on the tab itself, and the UI only frees up (and the tab page is rendered) once the bind is complete.

I communicated this to the client and mentioned the option of paging for each grid, but she is adament w.r.t. NOT wanting this. My only option then is to look for some asynchronous method of doing this in the background. I don't know much about threading in windows forms, but I know that I can use the BackgroundWorker control to achieve this. My only issue after reading up a bit on it is that it is ideally used for "long-running" tasks and I/O operations.

My questions:

  1. How does one determine a long-running task?
  2. How does one NOT MISUSE the BackgroundWorker control, ie. is there a general guideline to follow when using this? (I understand that opening/spawning multiple threads may be undesirable in certain instances)
  3. Most importantly: How can I achieve (asychronously) binding of the datagridview after the tab page - and all its child controls - loads.

Thank you for reading this (ahem) lengthy query, and I highly appreciate any responses/thoughts/directions on this matter!

Cheers!

© Stack Overflow or respective owner

Related posts about winforms

Related posts about datagridview