473,779 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Sta rt 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\test callback.txt",
true);
writer.WriteLin e (DateTime.Now.T oLongTimeString ());
writer.Close ();
}

protected void Application_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
Timer timer = new Timer (callback, null, 0, 5000);
}

Any help would be much appreciated.

Cheers,
Todd.
Nov 18 '05 #1
4 2682
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**@redbackdv d.com.au> wrote in message
news:f9******** *************** ***@posting.goo gle.com...
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_Sta rt 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\test callback.txt",
true);
writer.WriteLin e (DateTime.Now.T oLongTimeString ());
writer.Close ();
}

protected void Application_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
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.Threadin g.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_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
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**@redbackdv d.com.au> wrote in message
news:f9******** *************** ***@posting.goo gle.com...
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_Sta rt 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\test callback.txt",
true);
writer.WriteLin e (DateTime.Now.T oLongTimeString ());
writer.Close ();
}

protected void Application_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
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******* *******@TK2MSFT NGP11.phx.gbl>. ..
As i can see you have following
protected void Application_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
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**@redbackdv d.com.au> wrote in message
news:f9******** *************** ***@posting.goo gle.com...
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_Sta rt 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\test callback.txt",
true);
writer.WriteLin e (DateTime.Now.T oLongTimeString ());
writer.Close ();
}

protected void Application_Sta rt(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccount s);
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
2173
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 "Go" eats more and more RAM, is it normal? Can it be avoided? (In normal programs this is isn't a real problem). ! import Tkinter
8
3344
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 which represents a clock on a form, to which the original class has a reference. (MVC style) If the user clicks and holds the X button on the form
4
336
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 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)...
9
3078
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 System.Threading.ThreadInterruptedException System.Threading.ThreadStateException to see if I could get more information about why the thread stops running but that code is never executed. Any ideas on how I can debug this?
11
7565
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 code in the .elapsed event takes 1 secocond to complete, what happens? 1) Timer starts. 10 milliseconds later the code is executed and timer stops. When code is done, 1 seconds later, the timer continues. 10 milliseconds later the code is...
0
1658
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 "for(i=0;i<=3;i++)" where I set "myTimer = new Timer;" and the Eventhandler "myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);"
4
5376
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 adds a time stamp to the received event and adds it to a event queue. This works well (therfore not shown here). The queue fills up. Then I used a timer to check every millisecond for new events in the queue and send it to another thread...
7
6079
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 seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
10
1941
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 the service stops? Being new at this service stuff, I don't know if it holds state or memory and I need to stop all active timers or if the magical gc will come along and help out. Thanks, I hope that makes sense.
0
9636
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5373
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.