954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to stop the Thread which is running continuously?

Hi,
I am having an small application which is running in a thread and it is waiting for an event initially. As soon as if i clicked the START button, event will be enabled. From then onwards my entire application is running in WHILE (TRUE) loop. That means that i want to run my application continuously. As soon as if i clicked the STOP button, i am reseting the event and exiting the application. But here i am facing one problem. Once if i clicked the STOP button, my application is hanging. Can any one give me some ideas, to overcome this problem.

Additional Information: -

1) I have created the class library for my application. ( This creates DLL for my application )

2) In order to test my application, i have created the small form based application which will call my actual application

3) I have included that DLL as a reference in the reference list, in the Form based application

4) I have used the "ManualResetEvent" Class to handle the events.

Please give me the solution. It's urgent. Reply back to me if anyone needs more inputs.

Regards,
Vijay Bhaskar

chsarp_vijay
Newbie Poster
19 posts since May 2008
Reputation Points: 7
Solved Threads: 0
 

Instead of using a while(TRUE) loop can't you use a variable while(keepLooping) and when the stop button is pressed you change keepLooping to false?

$dunk$
Newbie Poster
23 posts since Mar 2008
Reputation Points: 14
Solved Threads: 5
 

Yeah, your problem is the while (true), you need to have some sort of shutdown flag, something like:

internal static bool Shutdown = false;

private static void Main()
{
     while (!Shutdown)
     {
             // Do stuff here
     }
}


And when you click your stop button, do "Shutdown = true;".

Webbsta
Light Poster
36 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

lanza kodaka threads nerchoko ra muttak na madda

kataraja5
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You