Posts

Showing posts with the label Invoke

C# / Threading - Progressbar with Database Transactions

To some, threading can be slightly confusing. If you happen to want to do a transaction on the computer you are writing the application for that may take a while, whether it be a database, communication with some PLC, saving large files, and happen to want to include a Progressbar, this sample may help. I am not going to step much into handling stepping with Progressbars, but rather the threading. It was found that thread pools are easily the ' weapon of choice ' when it comes to processing asynchronous I/O, post work items, etc. If you don't use threading, you may see that your application locks up for the length of time it takes to process these transactions. In terms of code, you do the following: using (SqlConnection sqlConn = new SqlConnection(String.Format("Data Source = {0}; User Id = {1}; Password = {2}; Timeout = 0; Integrated Security = True;", cboDatasources.SelectedItem.ToString(), txtUserName.Text, txtPassword.Text))) { // Open SQL Connection ...