Hello,
I'm not an expert on writing C# code, but I've been busy alot on a multithreaded application to manage database information. I've finally managed to get the multithreading part working, by using these forums and google, and I really would like to share something, because I think it can be annoying sometimes to get it to work right.
In my application I'm using alot of preload functions that run in a seperate thread, and a toolstripprogressbar to show the activity from 0 to 100%. Where 0 means the preload has begun, and 100 meaning the preload has ended. I'm not going to post the code on how to obtain the values because they are specific to the application, but I will post the code, rather line, for updating the toolstripprogressbar in a save way.
-
// Increment the progress bar.
-
this.BeginInvoke(new MethodInvoker(delegate()
-
{
-
this.progressMainBar.Increment(1);
-
}
-
));
-
I know this isn't exactly clean code, but it really does the trick in a nice way. It's probably nothing spectacular, but I can imagine people going crazy about the constant error messages that it's not allowed to access Form UI components from a seperate thread.
I hope it helps someone :)