I have created a windows service by using (Visual Studio 8) and installed it by using installutil.exe tool, however I am not getting proper result from it as I did the following code on service start method.
protected override void OnStart(string[] args)
{
FileStream fs = new FileStream(@"e:\mcWindowsService.txt",
FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine("m ready buddy");
m_streamWriter.Flush();
m_streamWriter.Close();
}
Instead of creating file in E Drive it is showing Following Error when I am staring it !
The Test Service Installer service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or program.
Put the above code in Try-Catch block, write it to event log for any exceptions and investigate it. Also would be good to put them in separate thread to avoid any block.