Stopping remote thread using bool

  • Thread starter Thread starter Eran.Yasso
  • Start date Start date
E

Eran.Yasso

Hi,

Is there a way to stop a loop running in a thread using bool?

What i mean is:

i have two classes.

When i click button(classA) on, i starts running s thread(classB) which
is located on other class.
The threas(while loop) runs while bool is equal to true.
when i click second button(classA), it sets that bool to fasle.
The loop(classB), sees that the bool is false, exits the loop and
terminating the thread.

thanks.
 
Is there a way to stop a loop running in a thread using bool?

What i mean is:

i have two classes.

When i click button(classA) on, i starts running s thread(classB) which
is located on other class.
The threas(while loop) runs while bool is equal to true.
when i click second button(classA), it sets that bool to fasle.
The loop(classB), sees that the bool is false, exits the loop and
terminating the thread.

Yes, that's basically fine. You need to be careful about the memory
model, however.

See http://www.pobox.com/~skeet/csharp/threads/shutdown.shtml for a
sample class.
 
thanks for the fast reply.

Shouldn't i use message que for that?

Why should you? The message queue is good for cross-process
communications where there's significant data, and where persistence
may be needed. I think it would be total overkill for this situation.
 
thanks for the fast reply.

Shouldn't i use message que for that?

I just thought that you might be talking about the Windows message
queue rather than MSMQ - in which case my answer is similar. I don't
see any benefit in using the UI queue when:
a) There may not be any UI involved
b) You're unlikely to have two threads both running a message queue
 

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

Back
Top