Windows Service won't start (udp listener)

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
 
B

Ben Voigt [C++ MVP]

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.
 
S

Snedker

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top