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

Generating an Event at a specific time

I'm performing a conversion of code from C to C# and I
want to perform a callback to a function where the
callback is performed at a certain time, like 2 March 2004
at 1:35pm.

I realise there are loads of timers in C#, but they all
perform repeatable events using an elapsed time which is
not what I desire.

The C code uses the functions
CreateWaitableTimer, SetWaitableTimer and
CancelWaitableTimer.

Is there an equivalent to this in C#
Nov 15 '05 #1
2 15231
1) Can wrap them easy and use pinvoke.
2) Can take the time now and time in the future you want to hit and take the
difference (timespan) and use the Timer class (or other) to wait for that
TimeSpan amount, then in the callback method, cancel the timer and do your
stuff. You can also reset the timer to go off again at some other point in
the future if needed.
3) If your doing a scheduler, use the timer class to call a method that
enums a collection to see if some job's time has expired and run a
method/delegate associated with that job if so. Set timer delay to the
largest delay that will still give you the resolution you need (i.e. every
60 seconds, every 30 seconds, etc.)

--
William Stacey, MVP

"dh****@ozemail.com.au" <an*******@discussions.microsoft.com> wrote in
message news:26****************************@phx.gbl...
I'm performing a conversion of code from C to C# and I
want to perform a callback to a function where the
callback is performed at a certain time, like 2 March 2004
at 1:35pm.

I realise there are loads of timers in C#, but they all
perform repeatable events using an elapsed time which is
not what I desire.

The C code uses the functions
CreateWaitableTimer, SetWaitableTimer and
CancelWaitableTimer.

Is there an equivalent to this in C#


Nov 15 '05 #2
"dh****@ozemail.com.au" <an*******@discussions.microsoft.com> wrote in
message news:26****************************@phx.gbl...
I'm performing a conversion of code from C to C# and I
want to perform a callback to a function where the
callback is performed at a certain time, like 2 March 2004
at 1:35pm.


public Timer SetTimer(TimerCallback callback,object state,DateTime when)
{
TimeSpan diff=when-DateTime.Now;
if(diff<TimeSpan.Zero)
diff=TimeSpan.Zero;
return new Timer(callback,state,(int)diff.TotalMilliseconds,-1);
}

HTH
Mike
Nov 15 '05 #3

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

Similar topics

10
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
1
by: A.Neves | last post by:
Hi, I have a DateTime in an Access database where I store one Date dd-mm-yyyy and a specific time HH:mm of the day for that date. How can I change the time without chaging the date and vice...
9
by: Andreas Lundgren | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
3
by: Just Me | last post by:
If I move the mouse cursor over a control and stop moving I get a MouseHover event. If I then move the cursor while staying within the control and then stop moving I do not get another...
1
by: Niron kag | last post by:
Hello! I want to run a specific program every day or month - in specific time automatically. Can you tell me please what is the best way to do it? Thank U!
1
by: Daz | last post by:
Hello everyone. I'm making a JavaScript clock which works in real time, and supports every time zone. I am struggling to find a way to see when the clocks are set back or forwards in a specific...
2
by: MrPogle | last post by:
I want to return the the date for the day before my query runs but at a specific time. The time is not midnight, so: convert(varchar(19),getdate() and '08:00:00',101) does not work. Instead I...
2
by: lancrye | last post by:
Hi, I placed on a userform a label that is showing the current system time - lblClock. In addition I placed few text boxes with different times. My problem is that I want to trigger an event...
2
by: bharathreddy | last post by:
This is insight I would like to share how to restrict application from doing some tasks on specific time in specific timezone. Like if we want to restrict our application to work only from...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.