How are you all,Again i came with threading problem.please solve me.
I am using C#.net Windows application. my application frequently execute the one
funtion.so i need to go thread.The main thread just execute the thread and return back.when i close the application the main thread stop thread.that is procedure. so i write code like this.
Main thread start the thread
Expand|Select|Wrap|Line Numbers
- private void start()
- {
- object synobject = new object();
- isthreadrunning = true;
- Thread t = new Thread(new ThreadStart(startthread)
- t.start()
- }
Expand|Select|Wrap|Line Numbers
- private void startthread()
- {
- while(true)
- {
- lock(synobject)
- {
- if (isthreadrunning == false)
- return;
- }
- Beginexecute()
- Thread.sleep(1000);
- }
- }
Expand|Select|Wrap|Line Numbers
- private void stop()
- {
- lock(synobject)
- {
- isthreadrunning == false;
- }
- t.abort();
- }
i wont access the form. is completely blocked. is there any problem in above coding. Please solve this problem..
Thanks in Advance,
Sekar.