I am trying to create a windows service that will read incoming data on a serial port.
This I have done more or less with the aid of a fantastic demo
http://msmvps.com/bl...2300_-.NET.aspx
The data from the serial port is continuous and is written to a database.
Now once the service starts, everything is hunky dory, but an error appears on the service startup
"Error 1053: The service did not respond to the start or control request in a timely fashion".
However, the service is doing what it is supposed to do and is running. But you cannot stop it in the services console. Well the service console says it can't start it, but it has.
I start the service by the usual means but there is a while loop involved which instantiates an event to onDataReceive. This spins round and round and writes the data to the database as long as there is data coming in and the port is open. But if I want to stop the service I am unable to break into that thread to stop the process.
So for the onstop method I enetered Base.Stop();
Everyhting I have tried so far doesn't work.
I think there maybe 2 issues.
One is that I cannot engineer a method to stop the service
Two thjat there is a mutli threading problem occurring, whereby I am unable to intercept a current event driven thread.
Please can someone point me in the right direction.
I was trying to monitor the state of the com port to see if it is open....well it's always open as long as there is data coming in on it. So that is not much good to me to monitor the state.
Now I'm thinking I should have another thread that monitors the service commands....onstart, onstop... but I feel this is not the correct way to do it.
Also I'm thinking there must be some kind of design pattern available to use. Is it all really that complicated?
Multi threaded Winows service c#Windows service will not stop - Error 1053
Page 1 of 1
5 Replies - 10399 Views - Last Post: 04 November 2008 - 07:11 AM
Replies To: Multi threaded Winows service c#
#2
Re: Multi threaded Winows service c#
Posted 03 November 2008 - 12:32 PM
The majority of the time this is caused from a lengthy process being called in the onstart event, remove this and place a timer in the onload event to allow it to load first, then call your process
#3
Re: Multi threaded Winows service c#
Posted 04 November 2008 - 01:32 AM
PsychoCoder, on 3 Nov, 2008 - 11:32 AM, said:
The majority of the time this is caused from a lengthy process being called in the onstart event, remove this and place a timer in the onload event to allow it to load first, then call your process
This is a windows sevrice not a win form app. There is no onload event.
#4
Re: Multi threaded Winows service c#
Posted 04 November 2008 - 02:29 AM
I meant onstart (I said right before that lol
)
#5
Re: Multi threaded Winows service c#
Posted 04 November 2008 - 04:01 AM
PsychoCoder, on 4 Nov, 2008 - 01:29 AM, said:
I meant onstart (I said right before that lol
)
Dugh!!!
Ok this did work. I also had the same problem with the onstop command of the service.
So I did as you said and split up the method into smaller ones. This did the trick!
Interesting that there is no other mention of the possibility that if your start and stop methods are large that the service won't start. I understand there is a timeout on the initial service start up to make sure the method can completed in time. If that method does not finalise then the Error 1053 makes its dastardly appearance!! Thanks for your input. It's greatly received!!
Thanks
#6
Re: Multi threaded Winows service c#
Posted 04 November 2008 - 07:11 AM
No problem, glad I could help
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|