473,586 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ManualResetEven t.WaitOne() and ManualResetEven t.Set()

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 sense WaitOne() method in
event handlers does not release the lock.

I have the following code in my class:
class MyClass
{
ManaualResetEve nt myResetEvent = ManualResetEven t(false);
Thread thread;

// This method changes controll from one thread to another. So in theory
I would like to let the
// thread asossiated with toNext excecute while blocking all other
threads.
private static void ChangeControl(M yClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thre ad.ThreadState & ThreadState.Uns tarted) ==
ThreadState.Uns tarted)
{
toNext.thread.S tart();
}
else
{
//Signal that currentActive is updated.
toNext.myResetE vent.Set();
}

from.myResetEve nt.WaitOne();
from.myResetEve nt.Reset();
}
}

Many thanks in advance.

Best regards from
Kovan Akrei
Nov 16 '05 #1
2 14524
Sorry Folks,
The text below should be like this:

I would love to know if it is possible some how to ensure that a thread T1
does not call T2.myResetEvent .Set() before T2 has blocked by calling
T2.myResetEvent .WaitOne()? I cant use monitors sense WaitOne() method in
event handlers does not release the lock.
Regards from Kovan

"Kovan Akrei" <ko****@ifi.uio .no> wrote in message
news:e2******** ******@tk2msftn gp13.phx.gbl...
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 sense WaitOne() method in
event handlers does not release the lock.

I have the following code in my class:
class MyClass
{
ManaualResetEve nt myResetEvent = ManualResetEven t(false);
Thread thread;

// This method changes controll from one thread to another. So in theory I would like to let the
// thread asossiated with toNext excecute while blocking all other
threads.
private static void ChangeControl(M yClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thre ad.ThreadState & ThreadState.Uns tarted) ==
ThreadState.Uns tarted)
{
toNext.thread.S tart();
}
else
{
//Signal that currentActive is updated.
toNext.myResetE vent.Set();
}

from.myResetEve nt.WaitOne();
from.myResetEve nt.Reset();
}
}

Many thanks in advance.

Best regards from
Kovan Akrei

Nov 16 '05 #2
"Kovan Akrei" <ko****@ifi.uio .no> wrote in message
news:eU******** ******@tk2msftn gp13.phx.gbl...
The text below should be like this:
I would love to know if it is possible some how to ensure that a thread T1
does not call T2.myResetEvent .Set() before T2 has blocked by calling
T2.myResetEvent .WaitOne()? I cant use monitors sense WaitOne() method in
event handlers does not release the lock.
Regards from Kovan
Why is this necessary? I can't see any reason.
---
Tom Tempelaere

"Kovan Akrei" <ko****@ifi.uio .no> wrote in message
news:e2******** ******@tk2msftn gp13.phx.gbl...
class MyClass
{
ManaualResetEve nt myResetEvent = ManualResetEven t(false);
Thread thread;

// This method changes controll from one thread to another. So in

theory
I would like to let the
// thread asossiated with toNext excecute while blocking all other
threads.
private static void ChangeControl(M yClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thre ad.ThreadState & ThreadState.Uns tarted) ==
ThreadState.Uns tarted)
{
toNext.thread.S tart();
}
else
{
//Signal that currentActive is updated.
toNext.myResetE vent.Set();
}

from.myResetEve nt.WaitOne();
from.myResetEve nt.Reset();
}
}

Nov 16 '05 #3

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

Similar topics

1
2305
by: Pujo Aji | last post by:
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,...
0
1418
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 at all without throwing an exception I had to include this "IntPtr handle=bev.Handle;" before the WaitOne call. -- Thanks, Mark
3
12591
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 ManualResetEvent. How do I ensure that _all_ waiting threads are signaled, without sacrificing any of the functionality or much of the simplicity of...
0
1066
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 moves on to the other line. Is there a specific process model I have to set in IIS? If I wrap it in a seperate thread will that help? Any help...
2
2805
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 threads of the same Sub and they are all unsignaled, how would I signal them (or one of them)? Here is a sample of my problem... Thanks!! ...
3
10388
by: Ed Sutton | last post by:
Can any one please offer any theories on how ManualResetEvent.WaitOne can hang when used with a timeout? When I notice my USB/Serial devices are no longer receiving communications, I hit break all, and one of the threads is hanging at: bool replyReceived = readerCommand.SignalReply.WaitOne(readerCmd.rxTimeOutMs, false); Apparently the...
2
2332
by: csharpula csharp | last post by:
Hello I am using the ManualResetEvent WaitOne and I have a question: I use it in order to wait for sometimeout and if some function wasn't activated by other process I should activate it myself. How can I know if some function was called during the Wait? Thanks! *** Sent via Developersdex http://www.developersdex.com ***
15
2916
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. Running some code - setting ManauelResetEvent.Reset(). The code continue - and somewhere else i test the handle
7
7186
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(). My expectation is that I would see the text generated in WasteTime() before seeing the "Hey" printout that comes after WaitOne(). Instead, I'm seeing...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.