By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,011 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

C# : Sharing something for the toolstripprogressbar.

Airslash
100+
P: 221
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.

Expand|Select|Wrap|Line Numbers
  1. // Increment the progress bar.
  2. this.BeginInvoke(new MethodInvoker(delegate()
  3.      { 
  4.            this.progressMainBar.Increment(1); 
  5.      }
  6. ));
  7.  
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 :)
Nov 30 '07 #1
Share this Article
Share on Google+
2 Comments


P: 3
Hello, now i have some problem to ask you how i write C# in console and conection with Database, please tell me
thank you
Dec 3 '07 #2

Airslash
100+
P: 221
Hello, now i have some problem to ask you how i write C# in console and conection with Database, please tell me
thank you
eum, well basicly, you need to include the right namespaces depending on what database you are using. For example
if you are using a MS Sql server: using System.Data.SqlClient and System.Data;

Then you need to have a connectionstring to connect to the database, either a DataReader, DataTable or DataSet to retrieve and store the information.
Dec 4 '07 #3