This project has moved. For the latest updates, please go here.

Windows Service Problem - this asynchronous object cannot be used with this synchronizationcontext

Aug 3, 2012 at 4:01 PM

Windows Service Problem.

 

I got this error

 

on this code  this asynchronous object cannot be used with this synchronizationcontext 

ListeningSocket = new SimpleServerTcpSocket();

Coordinator
Aug 3, 2012 at 7:23 PM

Win32 services do not provide a SynchronizationContext.

Try using ActionThread to provide your own SynchronizationContext.

Aug 4, 2012 at 8:29 AM
Edited Aug 4, 2012 at 8:29 AM

I try to use actionThread but i got same error i coded like this

 

ActionThread _actionThread
ServerProcess serverProcess
public void Start()
 {
            _actionThread = new ActionThread();
            _actionThread.Start();
            _actionThread.Do(() =>
                    {			
			serverProcess = new ServerProcess();
			serverProcess.StartListening(7750);
});
}
Aug 6, 2012 at 6:56 AM

is anybody out there ?

Coordinator
Aug 6, 2012 at 2:20 PM

What is "ServerProcess"?

Please keep in mind that I am the only maintainer for this project. I also maintain many other projects, and have a day job which doesn't pay me to provide free support to others. Oh, and I like to spend weekends with my family, not on CodePlex.

       -Steve

Aug 7, 2012 at 8:05 AM

Hi Steve ,

 

Thank you for your help. But i didnt write you. I understand you. causeI support some project like you. sorry for this misunderstanding. But so many people use this tool but doesnt support it. it is not nice. I wrrote this sentence for them

Ok then i resolve this. But i need litle help. My serverprocess is singleton class it is contain  some business rule and SimpleTcpserver and SimpleTcpCient. I run SimpleTcpserver in backgroundworker(BW). When i use BW i have got this error. I delete BW and its works fine with ActionThread.

 

But in SimpleTcpCient write_Completede event doesnt work or fired i dont Know why ? SimpleTcpCient is created in BW

 

Thanks for advice and Help

Coordinator
Aug 7, 2012 at 11:57 AM

You can't use BackgroundWorker with the socket classes, because BackgroundWorker doesn't provide a SynchronizationContext.

So you do need to run the sockets within ActionThread directly.

ActionThread is similar to BackgroundWorker, so I would try replacing BackgroundWorker with ActionThread. You'll have to do some "translation", but it would work better in the end.

        -Steve

Aug 7, 2012 at 2:56 PM

I do that but write_Completed event already hasnt fired. but i view sending data to server corectly?

Coordinator
Aug 7, 2012 at 6:37 PM

I'm not sure what the problem would be in that case.

Aug 8, 2012 at 9:38 AM

I resolve this. But I have a error but its different. I add new topic for this.