473,811 Members | 3,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AutoResetEvent. .WaitOne() Question

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 addition to it's normal
work load.

I created 5 AutoResetEvent objects and have the main thread call set when it
wants the worker thread to execute some additional code. In the worker
thread, I have 5 separate WaitOne(0,false ) functions being called; one for
each AutoResetEvent object . It was my hope that the worker thread would do
a quick check (no wait time) to see if the event was set and then proceed
with it's other work.

Unfortunately, there appears to be some overhead with this WaitOne()
function, because my CPU usage is running at about 70% when I have these 5
WaitOne() functions in the worker thread. However, if I comment them out,
the CPU usage drops to about 15%.

Does anyone know why this is such a drain on the system? Am I misusing
these Events? Is there a better or more efficient way to signal between
threads?

Thanks for your help.

Phil
Nov 16 '05 #1
2 12559
Phil,

I wonder why you would use a separate thread to do these operations.
Why not just put all of your work into thread pool requests (or at least
some of them)? You say yourself that you have an extra bit of code that
needs to be executed, which makes it a perfect candidate for a thread pool
operation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Phil" <Ph**@discussio ns.microsoft.co m> wrote in message
news:D4******** *************** ***********@mic rosoft.com...
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 addition to it's
normal
work load.

I created 5 AutoResetEvent objects and have the main thread call set when
it
wants the worker thread to execute some additional code. In the worker
thread, I have 5 separate WaitOne(0,false ) functions being called; one for
each AutoResetEvent object . It was my hope that the worker thread would
do
a quick check (no wait time) to see if the event was set and then proceed
with it's other work.

Unfortunately, there appears to be some overhead with this WaitOne()
function, because my CPU usage is running at about 70% when I have these 5
WaitOne() functions in the worker thread. However, if I comment them out,
the CPU usage drops to about 15%.

Does anyone know why this is such a drain on the system? Am I misusing
these Events? Is there a better or more efficient way to signal between
threads?

Thanks for your help.

Phil

Nov 16 '05 #2
The worker thread is reading from and writing to a com port. Ordinarily, it
would simply read from the com port, but there are occasions where the user
may need to send data back down to the device connected to the com port. So
I use Events to tell the thread to stop reading from the com port, send down
this data, and then resume reading from the com port. A special thread using
Events seems like the best solution for this scenario. Do you disagree?

Phil

"Nicholas Paldino [.NET/C# MVP]" wrote:
Phil,

I wonder why you would use a separate thread to do these operations.
Why not just put all of your work into thread pool requests (or at least
some of them)? You say yourself that you have an extra bit of code that
needs to be executed, which makes it a perfect candidate for a thread pool
operation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Phil" <Ph**@discussio ns.microsoft.co m> wrote in message
news:D4******** *************** ***********@mic rosoft.com...
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 addition to it's
normal
work load.

I created 5 AutoResetEvent objects and have the main thread call set when
it
wants the worker thread to execute some additional code. In the worker
thread, I have 5 separate WaitOne(0,false ) functions being called; one for
each AutoResetEvent object . It was my hope that the worker thread would
do
a quick check (no wait time) to see if the event was set and then proceed
with it's other work.

Unfortunately, there appears to be some overhead with this WaitOne()
function, because my CPU usage is running at about 70% when I have these 5
WaitOne() functions in the worker thread. However, if I comment them out,
the CPU usage drops to about 15%.

Does anyone know why this is such a drain on the system? Am I misusing
these Events? Is there a better or more efficient way to signal between
threads?

Thanks for your help.

Phil


Nov 16 '05 #3

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

Similar topics

2
14555
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 sense WaitOne() method in event handlers does not release the lock. I have the following code in my class: class MyClass
0
1219
by: donotreplymeonthisemail | last post by:
what does WaitOne(-1, true) do with exitContext set to true? i have not been able to understand this correctly. can i use this inside lock statement?
4
3199
by: Charles Law | last post by:
I've been using monitors a bit lately (some of you may have heard ;-) ) and then up pop Manual and AutoResetEvents , and they look for all the world like the same thing. Are they interchangeable, or when should I use one over the other? TIA Charles
1
3047
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 serial port is 23 bytes long, and is sent in response to a command. I begin timing before sending the command, and display split times when received data is signalled. The entire exchange of command and response is over within 6 ms (I have checked...
3
10421
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 1000ms rxTimeOutMs is not working. I have two threads
2
3562
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 waitone and allowing to wait for 2 mins. And then doing some processing.
5
9360
by: Maqsood Ahmed | last post by:
Hello, We have been experiencing a problem with AutoResentEvent class for past 2-3 months. It seems that it just stops at WaitOne and the thread doesn't released from blocking state. We have been using the following code for past 4 years, and It was working perfectly fine till Nov-Dec last year. I suspect a security update had messed it up. Please have a look at the following code.
3
10881
by: Morgan Cheng | last post by:
In order to arrange a time-out operation, I make the task running in a worker thread; and wait in main thread with AutoResetEvent help. The code is like below. AutoResetEvent ev = new AutoResetEvent(); if ( !ThreadPool.QueueUserWorkItem(WorkerProc, ev) ) { throw new ApplicationException("fail to queue task"); } ev.WaitOne(5000, false); //timeout == 5000 ms
4
5934
by: buu | last post by:
so, I have a private object as system.threading.AutoResetEvent, and I would like to read it's current status. currently I have an another boolean object wich I update together with an AutoResetEvent, but I don't think it's the best practice....
0
9730
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10392
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5555
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
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
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.