473,569 Members | 2,489 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
CreateWaitableT imer, SetWaitableTime r and
CancelWaitableT imer.

Is there an equivalent to this in C#
Nov 15 '05 #1
2 15252
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*******@disc ussions.microso ft.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
CreateWaitableT imer, SetWaitableTime r and
CancelWaitableT imer.

Is there an equivalent to this in C#


Nov 15 '05 #2
"dh****@ozemail .com.au" <an*******@disc ussions.microso ft.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(TimerC allback callback,object state,DateTime when)
{
TimeSpan diff=when-DateTime.Now;
if(diff<TimeSpa n.Zero)
diff=TimeSpan.Z ero;
return new Timer(callback, state,(int)diff .TotalMilliseco nds,-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
24462
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 to accomplish this in a different way? Best regards, Andreas Lundgren
1
2285
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 versa in a sepecific DateTime object. I need this because in a grid they are in separate columns but in the database they are in the same field. --...
9
2501
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 to accomplish this in a different way? Best regards,
3
3022
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 MouseHover event. To get a Mousehover I must leave and reenter the control. I'd like to get an event each time the cursor stops moving.
1
2228
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
2264
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 time zone. Is there any way I can find this out with PHP without having to use some kind of intensive loop, which will probably lag out my server? ...
2
10934
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 want to return the day before at 8am. Thanks.
2
7461
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 any time that the time in one of the text boxes is equal to the time in lblClock as long as the application is opened. Thanks in advance for your...
2
3228
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 12:01AM to 2:30PM EST and we don't know where the server is located and we don't know the timezone of the hosted application. DateTime dt =...
0
7703
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...
0
8132
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...
1
7678
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...
0
5222
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
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
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
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...

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.