C# Process.Start、Thread.IsBackGround、BackgroundWorker 和 .Net.Remoting

发布于 2024-10-24 04:26:37 字数 643 浏览 4 评论 0原文


我需要建议,因为我被“锁定”了...

我有一个客户端-服务器应用程序,在客户端进程和服务器进程之间使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

邮友 2024-10-31 04:26:37

您应该具备什么:

客户:
--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??

想你的星星会说话 2024-10-31 04:26:37

我找到了(a)解决方案:
在客户端启动中:

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

或(尚未测试哪一个)

RemotingConfiguration.ApplicationName = "EDV";

必须服务器进程启动之前设置!

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 !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文