Windows Service Problems

  • Thread starter Just close your eyes and see
  • Start date
J

Just close your eyes and see

Hello all
i am trying to learn how to program a windows service application
i had add an event log and a timer that used to write to file
here is the code

protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
timer1.Start();
}

protected override void OnStop()
{
eventLog1.WriteEntry("In onStop");
timer1.Stop();
}

protected override void OnContinue()
{
eventLog1.WriteEntry("In OnContinue");
timer1.Start();
}

FileStream fs;
StreamWriter sw;
private void timer1_Tick(object sender, EventArgs e)
{
fs = new FileStream(@"C:\tem.txt", FileMode.OpenOrCreate, FileAccess.Write);
sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(DateTime.Now.ToString());
sw.Flush();
sw.Close();
}


and i had added an installer to install the windows service, i followed the
instructions that is in the MSDN

http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx

first it works and installed but when i tried to run it from the windows
management console
it run and ends immediatly and i got a message telling me that some services
closed coze it is not doing anything

when i tried to make a new installation package, and reninstall the service,
the installation package failed to install the service and give me 2 messages
the first one saying that source of the service is on the local machine

and finally i got a meesage that the installation is interupted and ended
not successfuly


plz help to resolve that.....
 
C

Ciaran O''Donnell

I would say it must have thrown an expection in the logging to the event log.
Have you checked that part of the code and made sure you are using a valid
source for the event log entries etc?
 
J

Just close your eyes and see

here is my constructor code where i had initialized the event log

InitializeComponent();
if (!EventLog.SourceExists("TSNUpdatingWebApp"))
{
EventLog.CreateEventSource("TSNUpdatingWebApp",
"TSNUpdatingWebApp");
}
eventLog1.Source = "TSNUpdatingWebApp";
eventLog1.Log = "TSNUpdatingWebApp";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top