473,322 Members | 1,232 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,322 software developers and data experts.

Problems with Windows Service

I have created a simple service which just copies a fil to a new file
with a new name on certain intervals (the service implements a timer).
I have no problems installing the service and the log-entries I have
created on stop() and start() in the eventlog works fine as well.
However - the actual task is never executed. I catch the execution of
the tick and in the finally-block I write to the eventlog as well. But
only one entry is creates - namely with the first tick of the timer.
The data in eventlog is

The description for Event ID ( 0 ) in Source ( Application ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: Run of
service BackUpMemberData is complete.

The code for the service is included below - can any of you guys see,
what is wrong with it?

Thanks, :o)

public class BackupMemberData : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer timer = null;
private System.ComponentModel.IContainer components;

public BackupMemberData()
{
InitializeComponent();
double interval = 60000;
timer = new System.Timers.Timer(interval);
timer.Elapsed += new ElapsedEventHandler(this.Timer_Tick);
}

private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
System.Diagnostics.EventLog elog = new System.Diagnostics.EventLog();
elog.Source = "Application";
this.timer.Stop();
string Guid = System.Guid.NewGuid().ToString();
try
{
File.Copy("d:\\testsvc.txt","d:\\testsvc-" + Guid + "-" + DateTime.Now.ToString() + ".txt");
elog.WriteEntry("Backup of member data completed successfully.",EventLogEntryType.Information);
}
catch (System.IO.IOException ioe)
{
elog.WriteEntry(ioe.Message,System.Diagnostics.Eve ntLogEntryType.Error);
}
finally
{
elog.WriteEntry("Run of service BackUpMemberData is complete",System.Diagnostics.EventLogEntryType.Suc cessAudit);
}
this.timer.Start();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new BackupMemberData() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ServiceName = "Backup data (Sekretariat)";
}

protected override void OnStart(string[] args)
{
timer.AutoReset = true;
timer.Enabled=true;
timer.Start();
}

protected override void OnStop()
{
this.timer.AutoReset = false;
this.timer.Enabled = false;
}

protected override void OnPause()
{
this.timer.Stop();
}

protected override void OnContinue()
{
this.timer.Start();
}
}

--
Jesper Stocholm
http://stocholm.dk
Give a man a fish and he will have food for a day,
give a man an elephant, and he will have food for a week.
Nov 15 '05 #1
2 4688
DateTime.Now.ToString()
contains ':', which are not allowed in a File. Fix that and you'll be able
to run.

Here's how I create Windows Services:
I create a Windows Service
I create a Windows Application.
I create a Component class with it's own Start, Stop, Pause, Continue,
etc. methods.

I drop the component into the Service and into the Application. On the
application I add 4 buttons, Start, Stop, Pause, and Continue. From both
executables, I'll call these methods on the component. Now I can test all I
want with the Windows application, keeping in mind the Service limitations
and then be able to compile the service with confidence that it has been
well tested.

Take care,
Chris R.

"Jesper Stocholm" <j@stocholm.invalid> wrote in message
news:Xn************************@130.226.1.34...
I have created a simple service which just copies a fil to a new file
with a new name on certain intervals (the service implements a timer).
I have no problems installing the service and the log-entries I have
created on stop() and start() in the eventlog works fine as well.
However - the actual task is never executed. I catch the execution of
the tick and in the finally-block I write to the eventlog as well. But
only one entry is creates - namely with the first tick of the timer.
The data in eventlog is

The description for Event ID ( 0 ) in Source ( Application ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. The following information is part of the event: Run of
service BackUpMemberData is complete.

The code for the service is included below - can any of you guys see,
what is wrong with it?

Thanks, :o)

public class BackupMemberData : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer timer = null;
private System.ComponentModel.IContainer components;

public BackupMemberData()
{
InitializeComponent();
double interval = 60000;
timer = new System.Timers.Timer(interval);
timer.Elapsed += new ElapsedEventHandler(this.Timer_Tick);
}

private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
System.Diagnostics.EventLog elog = new System.Diagnostics.EventLog();
elog.Source = "Application";
this.timer.Stop();
string Guid = System.Guid.NewGuid().ToString();
try
{
File.Copy("d:\\testsvc.txt","d:\\testsvc-" + Guid + "-" + DateTime.Now.ToString() + ".txt"); elog.WriteEntry("Backup of member data completed successfully.",EventLogEntryType.Information); }
catch (System.IO.IOException ioe)
{
elog.WriteEntry(ioe.Message,System.Diagnostics.Eve ntLogEntryType.Error);
}
finally
{
elog.WriteEntry("Run of service BackUpMemberData is complete",System.Diagnostics.EventLogEntryType.Suc cessAudit); }
this.timer.Start();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new BackupMemberData() }; System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ServiceName = "Backup data (Sekretariat)";
}

protected override void OnStart(string[] args)
{
timer.AutoReset = true;
timer.Enabled=true;
timer.Start();
}

protected override void OnStop()
{
this.timer.AutoReset = false;
this.timer.Enabled = false;
}

protected override void OnPause()
{
this.timer.Stop();
}

protected override void OnContinue()
{
this.timer.Start();
}
}

--
Jesper Stocholm
http://stocholm.dk
Give a man a fish and he will have food for a day,
give a man an elephant, and he will have food for a week.

Nov 15 '05 #2
Chris R wrote :
DateTime.Now.ToString()
contains ':', which are not allowed in a File. Fix that and you'll be
able to run.
Arrrgh ... :) Thanks a lot - it did the trick.
Here's how I create Windows Services:
I create a Windows Service
I create a Windows Application.
I create a Component class with it's own Start, Stop, Pause,
Continue,
etc. methods.

I drop the component into the Service and into the Application.
On the
application I add 4 buttons, Start, Stop, Pause, and Continue. From
both executables, I'll call these methods on the component. Now I can
test all I want with the Windows application, keeping in mind the
Service limitations and then be able to compile the service with
confidence that it has been well tested.


Thanks for the advice :)

--
Jesper Stocholm
http://stocholm.dk
Give a man a fish and he will have food for a day,
give a man an elephant, and he will have food for a week.
Nov 15 '05 #3

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

Similar topics

15
by: anders | last post by:
Hi! I have a config file that looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <service> <wellknown mode="SingleCall"...
0
by: ccuthbert | last post by:
I have a MCMS 2002 site that we recently had several hotfixes installed. After installing the hotfixes, both AOL users and Earthlink users experience tha same problem, namely that intermittently...
3
by: Andi Twine | last post by:
Hi all, I really hope someone here can help ! I have designed and built an ASP.NET web service with Visual Studio .NET. The web service outputs some dummy XML data when its called with some...
5
by: Matthew Speed | last post by:
(About me: I know very little about writing server applications. I have done plenty of VB6 desktop app work but this is my first server program. I got it to work by modifying examples. I...
7
by: David Laub | last post by:
I've also posted this issue to a Sun/java formum, but since it appears to be an integration issue, this may be the better place to posr: I have written a dot net/c# Web Services doesn't fully...
3
by: Jay | last post by:
hi i am jay from bangalore i have one problem ,can u please help me out. i have one windows application and one windows service. from windows application i have to call one process "gpg" to...
0
by: myoungbl | last post by:
Note:I'm using VB.NET, .NET 2.0, to write a service application. So far I've only attempted to run it on the development machine. I'm have a couple of problems I can't quite figure out with a...
2
by: subsanta | last post by:
My computer has so many problems and ive looked around on the internet and ive managed to fix some of them. I know that i have a few viruses on my computer, but i cant get rid of them, in one case i...
3
by: Russ | last post by:
I have a Web Service that was originally created with .NET VC 2003, and subsequently converted to the 2005 version. It works fine when built as a debug version, and run on the workstation it was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.