Member Avatar for GermanD

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

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

Member Avatar for GermanD

I found the problem, the interval settings were wrong lol.

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

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.

int Task1Timeout = 10; // seconds
int Task2Timeout = 10; // minutes
DateTime LastTask1 = DateTime.Now;
DateTime LastTask2 = DateTime.Now;

TimeSpan timerTask1 = new TimeSpan(0, 0, Task1Timeout); 
TimeSpan timerTask2 = new TimeSpan(0,Task2Timeout,0);

//// _Tick(..)
if( DateTime.Now - LastTask1 >= timerTask1)
{
   DoTask1();
  LastTask1 = DateTime.Now;
}

if( DateTime.Now - LastTask2 >= timerTask2)
{
   DoTask2();
  LastTask2 = DateTime.Now;
}
Member Avatar for GermanD

Thanks alot, makes perfect sense...now i feel like a c# newb lol
Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.