Auto Run Procedures in Windows Application

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 8
Reputation: GermanD is an unknown quantity at this point 
Solved Threads: 0
GermanD GermanD is offline Offline
Newbie Poster

Auto Run Procedures in Windows Application

 
0
  #1
Feb 27th, 2008
Hi,

I'm sitting with a weird problem.
I created an application in C# 2005 Express. It has 3 timer controls in it.
The first timer runs as a clock (system clock) and once this timer reaches a specific time during the day it runs its procedure (this works fine)
The 2nd timer has its Interval set to 10min. So every 10 minutes it needs to run its procedure.(doesn't do it)
The 3rd timer has its Interval set to 10Sec. So every 10 second it needs to run its two procedures (doesn't do it either);

Now when i run this app in debug mode everything works perfect. Breakpoints are being reached all the time, I don't see any problems. But once i publish the app and install it on a users machine it doesn't always run the procedures :/

As u probably realized is that this application is an auto update app which auto updates data (retrieve data from webservice then update the local SQL database)

Any help would be greatly appreciated. I need to get this working by midday tomorrow.
Any other suggestions would be great.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Auto Run Procedures in Windows Application

 
0
  #2
Feb 27th, 2008
Sounds like a Timing issue <no pun intended>
First I dislike the use of timers for the very reason you have stated. Instead I prefer to use threads... but that is just me.

I suggest that you use the single timer to do all the work since it is all in the main thread anyway. Setup some TimeSpan vars to determine when an action should occur, and let the single timer act on it.

Jerry
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: GermanD is an unknown quantity at this point 
Solved Threads: 0
GermanD GermanD is offline Offline
Newbie Poster

Re: Auto Run Procedures in Windows Application

 
0
  #3
Feb 27th, 2008
I found the problem, the interval settings were wrong lol.

Originally Posted by JerryShaw View Post
I suggest that you use the single timer to do all the work since it is all in the main thread anyway. Setup some TimeSpan vars to determine when an action should occur, and let the single timer act on it.
Jerry
Sounds good could u maybe give me an example or help on how to do this?
One procedure needs to run a certain time of day (this could change to different times), 2nd procedure should run every 10 seconds and 3rd should run every 10 minutes.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Auto Run Procedures in Windows Application

 
0
  #4
Feb 27th, 2008
Pretty straight forward. Some vars for holding the amount of time. You can adjust these as needed in and reset the TimeSpan vars.
In the Tick event handler, evaluate if it is time to run that task, and then reset its Last time ran var.

You can also get creative and call those tasks as a new thread so that the timer can service the other tasks without waiting.

  1.  
  2. int Task1Timeout = 10; // seconds
  3. int Task2Timeout = 10; // minutes
  4. DateTime LastTask1 = DateTime.Now;
  5. DateTime LastTask2 = DateTime.Now;
  6.  
  7. TimeSpan timerTask1 = new TimeSpan(0, 0, Task1Timeout);
  8. TimeSpan timerTask2 = new TimeSpan(0,Task2Timeout,0);
  9.  
  10. //// _Tick(..)
  11. if( DateTime.Now - LastTask1 >= timerTask1)
  12. {
  13. DoTask1();
  14. LastTask1 = DateTime.Now;
  15. }
  16.  
  17. if( DateTime.Now - LastTask2 >= timerTask2)
  18. {
  19. DoTask2();
  20. LastTask2 = DateTime.Now;
  21. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: GermanD is an unknown quantity at this point 
Solved Threads: 0
GermanD GermanD is offline Offline
Newbie Poster

Re: Auto Run Procedures in Windows Application

 
0
  #5
Feb 28th, 2008
Thanks alot, makes perfect sense...now i feel like a c# newb lol
Regards
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC