Window Service Problems
-
Hello all i ma 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.....
-
Hello all i ma 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.....
Hi, I think this might help you: Simple Windows Service Example[^] Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hi, I think this might help you: Simple Windows Service Example[^] Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Yes I know that. :wtf: That's why I submitted the post. But the the difference between the post and your code is that the code in the post actually works.
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hello all i ma 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.....
I use the [System.Timers.Timer] object in my Windows Services: - System.Timers.Timer t; void OnStart(string[] args) { t = new System.Timers.Timer(); t.Interval = 1000; t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Enabled = true; } void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ... }