473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Timer thread stops running

I have an ASP.NET application and I would like to have some code run
on the server automatically once a day at a specified time.

I create a timer thread to call a simple callback in the
Application_Start method. It seems to call the callback once or twice
while the application starts up but appears to stop once the default
page is displayed. Here is the code below (from Global.asax.cs):

public static void ProcessAccounts (object state) {
StreamWriter writer = new StreamWriter (@"c:\temp\testcallback.txt",
true);
writer.WriteLine (DateTime.Now.ToLongTimeString ());
writer.Close ();
}

protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

Any help would be much appreciated.

Cheers,
Todd.
Nov 18 '05 #1
4 2628
the easiest way to do this is to drop a timer control onto your global.asax
designer. Then customize it like you normally would using the interval
settings. In the event handler you would just put your processaccounts code.
Let .net do the management work for you instead of you doing it.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Todd" <to**@redbackdvd.com.au> wrote in message
news:f9**************************@posting.google.c om...
I have an ASP.NET application and I would like to have some code run
on the server automatically once a day at a specified time.

I create a timer thread to call a simple callback in the
Application_Start method. It seems to call the callback once or twice
while the application starts up but appears to stop once the default
page is displayed. Here is the code below (from Global.asax.cs):

public static void ProcessAccounts (object state) {
StreamWriter writer = new StreamWriter (@"c:\temp\testcallback.txt",
true);
writer.WriteLine (DateTime.Now.ToLongTimeString ());
writer.Close ();
}

protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

Any help would be much appreciated.

Cheers,
Todd.

Nov 18 '05 #2

Alvin, thanks for your help.

The drag and drop of the timer control from the Components gallery
creates a server-based timer. My previous approach was creating a thread
timer.

The server-based timer appears to be basically working but I have two
new problems with this approach.

Firstly, it appears to fire the Elapsed event twice (one second apart)
each time the specified interval elapses (in my test case 15 seconds).

Second, I couldn't see how to easily set an initial elapse time followed
by regular intervals of a standard elapse time (as you can with the
System.Threading.Timer class).

Regards,
Todd
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
As i can see you have following
protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

what is the scope of the timer object?

I hope you are getting my drift.

In any normal language timer will disappear as soon as you left the Start.
In .NET it's at random (whenever GS will eat you timer).
the same goes to the callback.

George.
"Todd" <to**@redbackdvd.com.au> wrote in message
news:f9**************************@posting.google.c om...
I have an ASP.NET application and I would like to have some code run
on the server automatically once a day at a specified time.

I create a timer thread to call a simple callback in the
Application_Start method. It seems to call the callback once or twice
while the application starts up but appears to stop once the default
page is displayed. Here is the code below (from Global.asax.cs):

public static void ProcessAccounts (object state) {
StreamWriter writer = new StreamWriter (@"c:\temp\testcallback.txt",
true);
writer.WriteLine (DateTime.Now.ToLongTimeString ());
writer.Close ();
}

protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

Any help would be much appreciated.

Cheers,
Todd.

Nov 18 '05 #4
George - that was it. Thank-you very much.

Going to go and look for my brain now... :-P

"George Ter-Saakov" <no****@hotmail.com> wrote in message news:<es**************@TK2MSFTNGP11.phx.gbl>...
As i can see you have following
protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

what is the scope of the timer object?

I hope you are getting my drift.

In any normal language timer will disappear as soon as you left the Start.
In .NET it's at random (whenever GS will eat you timer).
the same goes to the callback.

George.
"Todd" <to**@redbackdvd.com.au> wrote in message
news:f9**************************@posting.google.c om...
I have an ASP.NET application and I would like to have some code run
on the server automatically once a day at a specified time.

I create a timer thread to call a simple callback in the
Application_Start method. It seems to call the callback once or twice
while the application starts up but appears to stop once the default
page is displayed. Here is the code below (from Global.asax.cs):

public static void ProcessAccounts (object state) {
StreamWriter writer = new StreamWriter (@"c:\temp\testcallback.txt",
true);
writer.WriteLine (DateTime.Now.ToLongTimeString ());
writer.Close ();
}

protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}

Any help would be much appreciated.

Cheers,
Todd.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about Tkinter. This little program, after pressing the...
8
by: theinvisibleGhost | last post by:
I think I've found a bug in the timer control. I've got a class which uses a timer control. It imports it from System.Windows.Forms This timer ticks once a second, and then updates a label...
4
by: Todd | last post by:
I have an ASP.NET application and I would like to have some code run on the server automatically once a day at a specified time. I create a timer thread to call a simple callback in the...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
0
by: Björn | last post by:
Hi, I have problems using the timer object in a C# Windows Service In my OnStart() Method of the Windows Service I declare a timer object "Timer myTimer = 0;" Than I have a loop...
4
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
10
by: Ryan | last post by:
Hello everyone, I have made a service that starts timers when it starts. I have another windows form application that stops and starts the service. Do I need to deal with any started timers when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.