473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15244
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
24445
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
2275
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
2498
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
3019
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
2221
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
2257
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
10917
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
7458
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
3224
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...
0
7328
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
7388
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...
0
7499
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
5631
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,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
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...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
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...

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.