Displaying a "Wait" message during a long process with C# Threading


 

Introduction:

A thread (is a lightweight process) is a single sequential flow of control within a program.

Threads can be used to isolate tasks during a single process.

During a long process displaying a wait message can be done with Threading.

Under the click button event, start the Threads. By clicking on the button it will start two threads,

one to start the application process and another a wait message window.

 

private void button1_Click(object sender, System.EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(executeTheProcess));
Thread t2 = new Thread(new ThreadStart(showWaitMessage));

t1.Start();
t2.Start();

}

private void executeTheProcess()
{
……..
// Process function

}

private void showWaitMessage()
{
……..
// wait message function
}

Output:

Download the source code – 9 kb

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!