views:

404

answers:

2

i have to run process in background using thread and background worker. this process do the task of retrieve data from database,it retrieve successfully by i can not display that data into datagridview, there is give some data error event. so,pls help me for this.

thanks .

A: 

May be you are unable to modify the DataGridView Control. Set CheckForCrossThreadcalls = false ,it may works

karthik
That's not good advice. That setting is there to alert the developer that they're doing something wrong. What you recommend is basically the same as telling someone if their smoke detector goes off just take out the batteries and go back to sleep.
Josh Einstein
...sure is peaceful without that bleeping....
Mitch Wheat
+1  A: 

BackgroundWorker has a built in callback method of RunWorkerCompleted that you wire into and it handles the cross thread marshaling to the UI thread automatically. Before you call RunWorkerAsync you can wire into the the RunWorkerCompleted event.

backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler( backgroundWorker1_RunWorkerCompleted);

within the backgroundWorker1_RunWorkerCompleted you can bind your grid or set the DataSource property to the DataTable and it will be on the UI thread.

If you have already done this and are getting errors it might just be an unhandled exception within the DoWork/threaded code itself. If that is the case wrap the RunWorkerAsync call in a try catch and see what you get.

Hope that help...

sadboy
+1 sadboy.Plus don't forget to synch with the gui.
ChrisBD