473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Stopping remote thread using bool

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.

Dec 24 '06 #1
4 1720
<Er********@gmail.comwrote:
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/t...shutdown.shtml for a
sample class.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 24 '06 #2

Jon Skeet [ C# MVP ] wrote:
<Er********@gmail.comwrote:
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/t...shutdown.shtml for a
sample class.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon Hi,

thanks for the fast reply.

Shouldn't i use message que for that?

Dec 24 '06 #3
<Er********@gmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 26 '06 #4
<Er********@gmail.comwrote:

<snip>
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gerhard Swart | last post by:
Hi all. I'm writing a queue browser that reads queues from a specified machine and then display the data that's on the queue. I am using the MessageQueue Class in .Net(C#). I get the problem...
0
by: 2G | last post by:
Hi I'm trying to safely stop a thread but as you might have guessed, I'm failing at it. GetCurrentThread seems to get the wrong handle, my form disappears when I try to stop the thread and it...
4
by: Heliotic | last post by:
Hi everyone, Currently I am working on an application that will perform a remote scan of a specified server using the following code: Type t = Type.GetTypeFromProgID(...
4
by: MSDousti | last post by:
Hi I have written a VB .NET app, which uses several threads. I thought that when the user closes the main window (when MainForm.closed event occures, and I call application.exit) all running...
1
by: deluded.soul | last post by:
Hi everyone, I am trying to use the boost multithreading library. I am having a problem as the join() function for the thread never returns. I am using a boolean variable to indicate when the...
11
by: Steve | last post by:
I'm having a problem with my Thread usage and I think the general design of how I'm working with them. My UI class calls a method in another class that does a lot of work. That "worker" class...
4
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.