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

ManualResetEvent.WaitOne() and ManualResetEvent.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
{
ManaualResetEvent myResetEvent = ManualResetEvent(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(MyClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thread.ThreadState & ThreadState.Unstarted) ==
ThreadState.Unstarted)
{
toNext.thread.Start();
}
else
{
//Signal that currentActive is updated.
toNext.myResetEvent.Set();
}

from.myResetEvent.WaitOne();
from.myResetEvent.Reset();
}
}

Many thanks in advance.

Best regards from
Kovan Akrei
Nov 16 '05 #1
2 14498
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**************@tk2msftngp13.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
{
ManaualResetEvent myResetEvent = ManualResetEvent(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(MyClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thread.ThreadState & ThreadState.Unstarted) ==
ThreadState.Unstarted)
{
toNext.thread.Start();
}
else
{
//Signal that currentActive is updated.
toNext.myResetEvent.Set();
}

from.myResetEvent.WaitOne();
from.myResetEvent.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**************@tk2msftngp13.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**************@tk2msftngp13.phx.gbl...
class MyClass
{
ManaualResetEvent myResetEvent = ManualResetEvent(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(MyClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thread.ThreadState & ThreadState.Unstarted) ==
ThreadState.Unstarted)
{
toNext.thread.Start();
}
else
{
//Signal that currentActive is updated.
toNext.myResetEvent.Set();
}

from.myResetEvent.WaitOne();
from.myResetEvent.Reset();
}
}

Nov 16 '05 #3

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

Similar topics

1
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...
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...
3
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...
2
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....
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....
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.