C# Process.Start、Thread.IsBackGround、BackgroundWorker 和 .Net.Remoting
我需要建议,因为我被“锁定”了...
我有一个客户端-服务器应用程序,在客户端进程和服务器进程之间使用 .NetRemoting。
服务器进程向调用方法的客户端引发事件。
然后,客户端使用 BackGroundWorker 将值传输到用户界面。
通常,当客户端启动时,服务器已经在运行。
- 当调用 BackGroundWorker.DoWork() 时,Thread.CurrentThread.IsBackground 等于 True
- 在 BackGroundWorker_RunWorkerCompleted 事件中,Thread.CurrentThread.IsBackground 等于 False
但是,如果在客户端加载期间(.exe 打开),则需要在连接之前打开(使用 Process.Start())服务器进程 (.exe)
那么,在 BackGroundWorker_RunWorkerCompleted 中,Thread.CurrentThread.IsBackground 仍然等于 True,并且在此线程中无法更改 UI。
在这种情况下,我需要打开另一个客户端(连接到同一服务器)才能有良好的行为。
这两种情况有什么区别?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该具备什么:
客户:
--UI线程:启动BGWorker并运行BackgroundWorker.RunWorkerCompleted
--Backgroundthread:运行BackgroundWorker.DoWork,与服务器通信
<->
服务器:与客户端通信
为什么当你的客户端启动时你的服务器还没有运行? + 如果它们在同一台机器上运行,为什么要使用远程处理?
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??
我找到了(a)解决方案:
在客户端启动中:
或(尚未测试哪一个)
必须在服务器进程启动之前设置!
I've found the (a) solution :
In the client startup :
or (haven't test wich one)
has to be set before Server process is started !