Windows Service won't start (udp listener)

  • Thread starter Thread starter Snedker
  • Start date Start date
S

Snedker

Hi folks,

If I outcomment the last four lines the service will start.

If I in-comment the line
"int recv = sock.ReceiveFrom(data, ref ep);"
the service will fail starting with error code 3534 (the service
reported no errors). Neither are errors written to the event log.

If I run the same code from a console application, everything works
fine.

The code:

protected override void OnStart(string[] args)
{
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
sock.Bind(iep);
EndPoint ep = (EndPoint)iep;
byte[] data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0,
recv);
data = new byte[1024];
}

Any ideas why that particular line prevents service from starting?

Regards
Morten Snedker
 
Snedker said:
Hi folks,

If I outcomment the last four lines the service will start.

If I in-comment the line
"int recv = sock.ReceiveFrom(data, ref ep);"
the service will fail starting with error code 3534 (the service
reported no errors). Neither are errors written to the event log.


Any ideas why that particular line prevents service from starting?

Yeah, you aren't allowed to use blocking calls from the main thread of a
service, it has to return to the Service Control Manager.
 
Yeah, you aren't allowed to use blocking calls from the main thread of a
service, it has to return to the Service Control Manager.

Yup - that was it. Thanks for your help!

Regards /Snedker
 
Back
Top