I have a windows form app as follows. I would like to make conditional transactions according to current time.Lets say if time is 11 and minute is between 10 and 15 then do this else do other thing on run time. How can I do it?
Best Regards.
Here is my sample code:
[STAThread] static void Main() { DateTime td = DateTime.Now; int hour = td.Hour; int min = td.Minute; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (hour >= 11 && hour < 12 && min >= 10 && min < 15) { Application.Run(new Form1(hour, min)); } else { Application.Run(new Form1()); } }
VulpesPosted Jan 4, 2012, 7:11 AM
However, you could do this:
Notice that the accuracy of the System.Windows.Forms.Timer leaves something to be desired but, if you set it to fire at 11.05, it should certainly remain within the desired interval even if the program is running continuously for a number of days.
If the program is running 'for ever', it might be a good idea to recalibrate it each time it fires.
RaysefoPosted Jan 5, 2012, 2:09 AM
as soon as I enabled the timer , It worked !
Thanks.
VulpesPosted Jan 4, 2012, 9:47 AM
RaysefoPosted Jan 4, 2012, 7:48 AM
It does NOT helping me to trigger the tick event after the application is running.
Here is my main:
And Here is Form_Load:
RaysefoPosted Jan 4, 2012, 6:35 AM
Thanks for your help.I wonder is there a way to set this Timer for a specific time interval? I mean everyday between 23:00 and 23:10.
Best Regards.
VulpesPosted Jan 4, 2012, 6:14 AM
RaysefoPosted Jan 4, 2012, 6:03 AM
VulpesPosted Jan 4, 2012, 4:55 AM
All you need to do is to add an extra constructor to Form1 which takes two int parameters: hour and minute, save them to fields on the form and you're there.