Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Choosing a thread control strategy

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacob - 25 Feb 2008 06:50 GMT
Ok, I have a C# program (server program) which needs to do the following:
Receive messages from a webapp via WCF and notify the server that it has
received a new transaction.  These transactions have a definite end date.  
I've got the WCF setuff set up, and basically the server program just needs
to sort the transaction (think auction-ish) showing the next one to end.  
Once it ends, the server program needs to do some work associated with the
transaction.

The problem I've run into is a conflict between how to handle the various
pieces.  I want the server process to Sleep (I guess Threading.Sleep) until
whenever the next transaction is scheduled to end.

However, I also need the server to be available to calculate the time until
the next transaction ending whenever a new transaction comes in (in case its
endtime is sooner than anything else in the system).  I was thinking an
AutoResetEvent for this, but if I am using that then it waits until the event
is set before releasing.  So, if a transaction ends it won't be processed
until another one comes in and sets the event.  However, using sleep, the
thread will be asleep and won't be available to catch the event for the new
transactions immediately as I understand it.

What I need is some sort of blend of Sleep and a ResetEvent, like a
ResetEvent with a timer on it that will wake either when the flag is set or
when a certain amount of time passes.  Is there any such thing, or can
somebody suggest another way to implement this?

Thanks in advance
Marc Gravell - 25 Feb 2008 07:02 GMT
> What I need is some sort of blend of Sleep and a ResetEvent, like a
> ResetEvent with a timer on it that will wake either when the flag is set or
> when a certain amount of time passes.  Is there any such thing, or can
> somebody suggest another way to implement this?

All the main locking constructs have this functionality - just look at
the overloads; for AutoResetEvent/ManualResetEvent, this would be
"WaitOne(timeout, false)". The bool return tells you whether you got
signalled vs a timout. Of course, you'll need to calculate a suitable
amount of time to wait, or check some other condition on waking...

Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.