Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I have developed a windows service in C#, whose startup type is Automatic. OnStart() method writes some values in a text file. My service works perfect in windows 7. But when I installed it in windows 8, the OnStart() method is not executed (as it does not write value in text file). Other methods of service which also write values in text file work perfectly in windows 8 also. Can anyone help me regarding this issue. Below is my OnStart() method code. Thanks in advance.

C#
protected override void OnStart(string[] args)
{
	FileStream fs = new FileStream(logFilePath, FileMode.OpenOrCreate, FileAccess.Write);
	StreamWriter sw = new StreamWriter(fs);
	sw.BaseStream.Seek(0, SeekOrigin.End);
	sw.WriteLine("some value");
	sw.Flush();
	sw.Close();
}
Posted
Comments
Akbar Ali Hussain 7-Aug-13 17:36pm    
Check the Event Viewer to verify is there any errors logged

1 solution

HAve you tried attacing your IDE to the process and then Test the application?

In you IDE select Tools from the menu then "Attach to Process"

Select your service and step through your code.

Alternatviely test the function in a forms application first using windows 8. Chances are the service does start but then ends because of an exception being thrown that you are not aware of.

You can also display a message box in the catch portion of a try catch statement, but remember to set the service to allow communiction with the desktop otherwise the messagebox function will also be ignored.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900