Beginner:Window Not Responding While Program Loops

S

Shamrokk

My application has a loop that need to run every 2 seconds or so. To
acomplish this I used...
"Thread.Sleep(2000);"

When I run the program it runs fine. Once I press the button that starts the
looping function the window becomes unmovable and cannot close under its own
direction (the upper right "close 'X'")

My first attempt to solve the problem was to have the looping function
execute as its own thread, the idea being this would leave the main thread
open to keep the window intact while the looping function executed in the
background of the program.

Here's a basic breakdown of the code...



public void btnStart_Click(object sender, System.EventArgs e)

{

Thread GoThread = new Thread(new ThreadStart(Go));

GoThread.Start();

}


public void Go()

{

//loop code here withe Thread.Sleep(2000); inside the end of each loop

}



My question is...

How do I keep the loop running without the window locking up?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top