views:

645

answers:

2

Hi,

following scenario. I have a datagridview and a progressbar, datagridview is being filled with some datas from active directory. Filling my datagridview takes about 3 minutes. Now, while my program is working everything is fine until I switch windows - like for example open web browser or anything else. When I swich back to my program the whole window is "frozen", progressbar is not showing any progress until filling is completed. How can I refresh my datagridview and progressbar so that something like this doesn't happen anymore? I've tried datagdidview.Invalidate() and Refresh() run every 5s (via Timer, yes it was enabled) but it doesn't work. What am I missing here?

Thanks!

+2  A: 

You need to run the UI and work methods on different threads otherwise the UI will lock when your datagridview is working.

Jonas B
+3  A: 

You should fetch the data in a separate thread (e.g. using BackgroundWorker or a new thread), marshalling back to the UI thread (with BackgroundWorker.ReportProgress on Control.Invoke/BeginInvoke) when you need to interact with the UI. See this article for more information and sample code.

Jon Skeet