473,399 Members | 2,146 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,399 software developers and data experts.

WaitOne question

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 ***
Aug 8 '06 #1
2 2320
The WaitOne overload with a timeout returns a boolean to indicate whether
you are returning because of activation or timeout; is this what you are
looking for?

Marc
Aug 8 '06 #2
csharpula csharp wrote:
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 ***
Here are some sample code from MSDN :
class WaitOne
{
static AutoResetEvent autoEvent = new AutoResetEvent(false);

static void Main()
{
Console.WriteLine("Main starting.");

ThreadPool.QueueUserWorkItem(
new WaitCallback(WorkMethod), autoEvent);

// Wait for work method to signal.
if(autoEvent.WaitOne(1000, false))
{
Console.WriteLine("Work method signaled.");
}
else
{
Console.WriteLine("Timed out waiting for work " +
"method to signal.");

** You can set the event here by yourself **
}
Console.WriteLine("Main ending.");
}

static void WorkMethod(object stateInfo)
{
Console.WriteLine("Work starting.");

// Simulate time spent working.
Thread.Sleep(new Random().Next(100, 2000));

// Signal that work is finished.
Console.WriteLine("Work ending.");
((AutoResetEvent)stateInfo).Set();
}
}
Aug 8 '06 #3

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...
2
by: Phil | last post by:
I have an application that has a main thread and a worker thread. From time to time, the main thread, because of user input, needs to notify the worker thread to execute an extra bit of code, in...
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...
1
by: Charles Law | last post by:
I have a frustrating problem where WaitOne does not return when I expect. I am using an AutoResetEvent with an overlapped structure in a call to WaitCommEvent. The data I am expecting on the...
2
by: Jon Paugh | last post by:
Hi, Can anyone explain the difference between the WaitOne vs. WaitAny methods on the IAsyncResult.AsyncWaitHandle object? They both wait for one, but the any seems to have different criteria...
3
by: ano | last post by:
How to reset Mutex.ReleaseMutex()? I can't call Mutex.WaitOne() again because the Mutex status seem to be fix to ReleaseMutex(). Do I need to create new Mutex() every time after ReleaseMutex()? ...
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: archana | last post by:
Hi all, I am not clear regarding waitone of manualresetevent. I am invoking webrequest asynchronously with say 5 requests at a time. What i am doing is after invoking request i am calling...
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: 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
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,...
0
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...
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
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,...

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.