简体   繁体   中英

C# Process.Start, Thread.IsBackGround, BackgroundWorker and .Net.Remoting


I need an advice because I'm "locked"...

I have a client-server application using .NetRemoting between the client process and the server one.
Server process raises events to the client calling a method.
Then, the client uses a BackGroundWorker to transmit values to User Interface.

Usualy, the server is already running when the client is launched.
- When BackGroundWorker.DoWork() is called, Thread.CurrentThread.IsBackground equals True
- In BackGroundWorker_RunWorkerCompleted event, Thread.CurrentThread.IsBackground equals False

But, if, during the client is loading (.exe is opening), it needs to open (with Process.Start()) the Server process (.exe) before it connects
then, in BackGroundWorker_RunWorkerCompleted, Thread.CurrentThread.IsBackground is still equal to True and UI can not be changed in this thread.
In that case, I need to open an other client (connecting to the same server) to have a good behavior.


What could be the difference between these two situations ?
Thanks.

What you should have:

Client:
--UI thread: starts BGWorker and runs BackgroundWorker.RunWorkerCompleted
--Backgroundthread: runs BackgroundWorker.DoWork, communicates with server

<->

Server: communicates with client

Why isn't your server already running when your client is starting? + Why use remoting if they're running on the same machine??

I've found the (a) solution : In the client startup :

lChannelTCP = new TcpChannel(lProps, provider, providerSrv);
ChannelServices.RegisterChannel(lChannelTCP, false);

or (haven't test wich one)

RemotingConfiguration.ApplicationName = "EDV";

has to be set before Server process is started !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM