Sleeping in a thread run from a new ThreadStart()

I have a program that is executing some calculations and I need to update the GUI in the meantime while also being able to pause or stop the program.

I have a UpdateGUI() method that sleeps for some time and then updates some GUI elements. I know this is not the correct way to do things but it is just for the initial part until I have things more clear.

Anyway, to simplify things I have two threads that I create from the GUI class as

Thread thCmd = new Thread(new ThreadStart(someFun()); Thread thGUI = new Thread(new ThreadStart(UpdateGUI());

UpdateGUI() gets some information from some objects and puts it in the screen. It looks something like this

UpdateGUI(){ while(simulationRunning){ Thread.Sleep (50); DoSomeThingsOnGui(); } } 

When I do this I expect to be able to control the application since both threads are different from the main thread where the GUI is. However I notice that when UpdateGUI() is working I can't control the application therefore I assume Thread.Sleep() doesn't actually sleep the thread thGUI but rather the GUI thread somehow. There's gotta be a way to Sleep only thGUI.

Any ideas?

by eclipseadb via /r/csharp

Leave a Reply