473,388 Members | 1,177 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,388 software developers and data experts.

ManualResetEvent choose which thread?

Hello,

I use ManualResetEvent to stop and allow a thread running by setting:
public static ManualResetEvent mre = new ManualResetEvent(false);

So if I use mre.WaitOne(); this let the thread stop
and I can use mre.Set to let the thread do it's process.

The problem is can I use this kind of mechanism to choose which thread
should run, for example I have two threads which in their inside code
there is mre.WaitOne() command.

Then in my code I would like to let the thread 1 only run, by setting
mre.Set().
But the fact is all of my thread are running just after I click mre.Set().

Thanks in advance.
--
Baby Step, One Step at a time, better and better....
Nov 16 '05 #1
1 2291
Hi Pujo,

A ResetEvent will not let you choose which thread starts running again.
However, you can ensure that only one thread starts (even though you can't
choose which) by using an AutoResetEvent instead.
As soon as a thread returns on the WaitOne() call, the event is
automatically immediately reset so no other threads will run.

Regards,

Rob
http://roblevine.blogspot.com

"Pujo Aji" <aj****@yahoo.com> wrote in message
news:opskju9aghd3sg8l@ajinote...
Hello,

I use ManualResetEvent to stop and allow a thread running by setting:
public static ManualResetEvent mre = new ManualResetEvent(false);

So if I use mre.WaitOne(); this let the thread stop
and I can use mre.Set to let the thread do it's process.

The problem is can I use this kind of mechanism to choose which thread
should run, for example I have two threads which in their inside code
there is mre.WaitOne() command.

Then in my code I would like to let the thread 1 only run, by setting
mre.Set().
But the fact is all of my thread are running just after I click mre.Set().

Thanks in advance.
--
Baby Step, One Step at a time, better and better....
Nov 16 '05 #2

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

Similar topics

2
by: Kovan Akrei | last post by:
Hi, I would love to know if it is possible some how to ensure that a thread T1 does not call T2.myResetEvent.Set() before T1 has blocked by calling T1.myResetEvent.WaitOne()? I cant use monitors...
0
by: Mark | last post by:
Hi, How do I stop a ManualResetEvent.WaitOne from intermittently jumping to 0? I am using version 1.1 of the framework. My ManualResetEvent instance is named "bev". To make the WaitOne work...
3
by: Elhurzen | last post by:
X-No-Archive: Yes >From what I understand, if multiple threads are waiting on a ManualResetEvent after calling WaitOne(), only one thread is guaranteed to be signaled when Set() is called on that...
0
by: Tomasz Kaszuba | last post by:
Is it possible to use the ManualResetEvent in my ASP.NET application? When I try to use it Asp.Net ignores the call to ManualResetEvent.WaitOne() (which should hold the thread indefinetly) and...
2
by: Brian Mitchell | last post by:
I am sure this is pretty basic but I have never worked with ResetEvents before, but how do I signal a ManualResetEvent of a module that is spun off into several threads? For instance, if I have 5...
24
by: Chad Everett | last post by:
Hey guys, I am back. Trying to expand on a program that was given in the book I am studying. No I am not a high school or college student. Doing this on my own. and having way to much...
15
by: Peter Larsen [] | last post by:
Hi, I have a problem using a ManuelResetEvent in the GUI thread while receiving events from the Shell (new folders, rename etc). This is what i do: Receiving an event from the Shell....
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
7
by: =?Utf-8?B?cmJEZXZlbG9wZXI=?= | last post by:
The following is from a simple Windows application in VS2005, which has button1 and textbox1 dragged onto a form. In StartThreads(), I call ThreadPool.QueueUserWorkItem(), then call WaitOne()....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.