Hi Experts,
I am having a ultrawingrid which is used to display the filepaths in column1 and progressbar in column2 i want to import the file from the path (displayed in col1) to the database and while inserting the records i have to show the percentage in progressbar column.. For this purpose i have used Background worker with methodinvokers. It works correctly for 8 out of 10 times. But suddenly its showing an unhandled error and my ultrawingrid is marked with a big 'X' mark.. what may be the problem. i have used try catch too but i cant handle that error...
.
Okay, I'm really confused. If this method is called on a background worker and you are checking InvokeRequired, then this will always be true and you are marshalling this method back to the UI Thread.
So the thread is completely pointless. You are doing everything on the UI Thread, anyway. Unless there is some other code being run on the background thread.
As for how to do this the correct way, I would just ditch the threading altogether and update the progress bar cells synchronously. If you must do it asynchronously, then I would recommend using a Windows Forms Timer, which operates on the UI Thread.
i have written this code in a seperate function and i have called this function within backgroundworker_dowork() event.....
Yes Mike. i understood what you r saying. So please give me any alternative solution and how to do it please..... and also please send me any samples
From what event is this code being called?
The exception you are getting here is almost certainly a threading issue.
As I mentioned (several times) in the other thread you posted, you cannot mix DataBinding and multiple threads. Your use of InvokeRequired and BeginInvoke here will not help, because there is all sorts of communication going on between the grid, the BindingManager, and the data source over which you have no control.
Are you sure you aren't updating any data on a different thread elsewhere in your program?
You can try suppressing the repaint during your update (this is good practice anyhow):
Before the initial Try add (replace '_grid' with the name of your grid):
_grid.BeginUpdate()_grid.SuspendRowSynchronization()
Create a Finally block for the Try/Catch surrounding your entire method and add:
_grid.ResumeRowSynchronization()_grid.EndUpdate()
This is the error.....