Hi,
I am writing a windows service with threading.timer for 10 seconds but
it didn't work. Here are my code:
namespace SchedulerServic e
{
public class ScheduleService : System.ServiceP rocess.ServiceB ase
{
private System.Componen tModel.IContain er components;
protected System.Threadin g.Timer tmrThreadingTim er;
public ScheduleService ()
{
InitializeCompo nent();
tmrThreadingTim er = new System.Threadin g.Timer(new
TimerCallback(t mrThreadingTime r_TimerCallback ), null,
System.Threadin g.Timeout.Infin ite, 1000);
}
[STAThread]
static void Main()
{
System.ServiceP rocess.ServiceB ase[] ServicesToRun;
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new
ScheduleService () };
System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}
private void InitializeCompo nent()
{
this.CanPauseAn dContinue = true;
this.CanShutdow n = true;
this.ServiceNam e = "SchedulerServi ce";
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
protected override void OnStart(string[] args)
{
tmrThreadingTim er = new System.Threadin g.Timer(new
TimerCallback(t mrThreadingTime r_TimerCallback ), null, 0, 10 * 1000) ;
//run 10 second each time
}
protected override void OnStop()
{
tmrThreadingTim er.Change(Syste m.Threading.Tim eout.Infinite,
System.Threadin g.Timeout.Infin ite);
}
private void tmrThreadingTim er_TimerCallbac k(object state)
{
Console.WriteLi ne("I am running");
}
}
Any help? 2 8463
Hi,
Just a quick question.. How do you expect to get information into the
console??
The reason I ask this is simple. You cannot run a Windows Service without
having to install it using RegSvc (to install the service) and then Net Start
(to start the service). If you try to run a service from inside the VS.NET
IDE and wait long enough(about 20-30 seconds) you will get an error stating
that it must be installed etc...
Hope this helps a little...
"hnkien" wrote: Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code:
namespace SchedulerServic e { public class ScheduleService : System.ServiceP rocess.ServiceB ase { private System.Componen tModel.IContain er components; protected System.Threadin g.Timer tmrThreadingTim er;
public ScheduleService () { InitializeCompo nent(); tmrThreadingTim er = new System.Threadin g.Timer(new TimerCallback(t mrThreadingTime r_TimerCallback ), null, System.Threadin g.Timeout.Infin ite, 1000); }
[STAThread] static void Main() { System.ServiceP rocess.ServiceB ase[] ServicesToRun; ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new ScheduleService () }; System.ServiceP rocess.ServiceB ase.Run(Service sToRun); }
private void InitializeCompo nent() { this.CanPauseAn dContinue = true; this.CanShutdow n = true; this.ServiceNam e = "SchedulerServi ce"; } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Disp ose(); } } base.Dispose( disposing ); }
protected override void OnStart(string[] args) { tmrThreadingTim er = new System.Threadin g.Timer(new TimerCallback(t mrThreadingTime r_TimerCallback ), null, 0, 10 * 1000) ; //run 10 second each time }
protected override void OnStop() { tmrThreadingTim er.Change(Syste m.Threading.Tim eout.Infinite, System.Threadin g.Timeout.Infin ite); }
private void tmrThreadingTim er_TimerCallbac k(object state) { Console.WriteLi ne("I am running"); }
}
Any help?
Hi,
How it's not working?
In the other hand you create the timer twice once in the constructor and
another in the OnStart()
Remove one ( I would remove the one in the constructor )
Then install the service in debug mode, attach the debugger to the process
and put a breakpoint in the timer method, if it does stop it's working ,
only that you cannot use the console
No sure now where the console output goes in this case.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"hnkien" <hn******@yah oo-dot-com.no-spam.invalid> wrote in message
news:41******** **@Usenet.com.. . Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code:
namespace SchedulerServic e { public class ScheduleService : System.ServiceP rocess.ServiceB ase { private System.Componen tModel.IContain er components; protected System.Threadin g.Timer tmrThreadingTim er;
public ScheduleService () { InitializeCompo nent(); tmrThreadingTim er = new System.Threadin g.Timer(new TimerCallback(t mrThreadingTime r_TimerCallback ), null, System.Threadin g.Timeout.Infin ite, 1000); }
[STAThread] static void Main() { System.ServiceP rocess.ServiceB ase[] ServicesToRun; ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new ScheduleService () }; System.ServiceP rocess.ServiceB ase.Run(Service sToRun); }
private void InitializeCompo nent() { this.CanPauseAn dContinue = true; this.CanShutdow n = true; this.ServiceNam e = "SchedulerServi ce"; } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Disp ose(); } } base.Dispose( disposing ); }
protected override void OnStart(string[] args) { tmrThreadingTim er = new System.Threadin g.Timer(new TimerCallback(t mrThreadingTime r_TimerCallback ), null, 0, 10 * 1000) ; //run 10 second each time }
protected override void OnStop() { tmrThreadingTim er.Change(Syste m.Threading.Tim eout.Infinite, System.Threadin g.Timeout.Infin ite); }
private void tmrThreadingTim er_TimerCallbac k(object state) { Console.WriteLi ne("I am running"); }
}
Any help? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ray |
last post by:
Hi,
I just wrote a windows service application to call a function of another
object periodically. I used System.Server.Timer and I found that it works
fine within the first 2 hours but the onTimer event wouldn't be raised again
after few hours. I checked the msdn and Microsoft claims that it is a bug in
their .net framework as follows:
http://support.microsoft.com/default.aspx?scid=kb;en-us;842793
|
by: J. Hill |
last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called.
Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows form and it works fine, but in the service: nothing.
....
this.components = new System.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
|
by: Dhilip Kumar |
last post by:
Hi all,
I have developed a windows service using the windows service project
template in VS.NET. I have used three controls in the service, a timer,
performance counter and a message queue control. The service will "sleep"
for 'n' seconds using the timer control and whenever the timer_elapsed event
occurs, I use the performance counter object to determine availability of
few resources. Based on the availability of resources, I use the...
|
by: John David Thornton |
last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and
I've coded it as shown below. However, when I install the service and then
start it in MMC, I get a peculiar message:
The MyService service on Local Computer started and then stopped. Some
services stop automatically if they ahve no work to do, for example, the
Perforamnce Logs and Alert service.
I tried switching to a System.Threading.Timer and that didn't work...
|
by: archana |
last post by:
Hi all
I am having application which is using server based timer that is timer
from namespace system.timer.
I am having windows service which i want to run everyday at some fix
time.
In service.cs class i am creating one worker thread and in thread
procedure i am enabling one timer after thread procedure is completed
and in timer's elapsed event i am recalling my function of actual
processing.
| |
by: archana |
last post by:
Hi all
I am having application which is using server based timer that is timer
from namespace system.timer.
I am having windows service which i want to run after every 1 hour and
after every one hour i am sending mail.
In service.cs class i am creating one worker thread and in thread
|
by: Lemune |
last post by:
Hello everyone.
I'm using vb 2005. I'm creating program that run as service on windows.
And in my program I need to use timer, so I'm using timer object from
component. I try my source code on another project that use windows
form and it work. But when I implement my source code on my program
that run as service on windows (I have change the code so it would work
on service but I still use timer object from component), and it doesn't...
|
by: Tony Gravagno |
last post by:
I have a class that instantiates two Timer objects that fire at
different intervals. My class can be instantiated within a Windows
Form or from a Windows Service. Actions performed by one of the event
handlers may take longer than the interval for either of the timers,
so it's possible for multiple events to fire "simultaneously" and for
events to queue up. I'm attempting to get the timers to sync on some
reference type object, or use...
|
by: igor |
last post by:
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework....
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |