Windows窗体GUI线程无响应 [英] Windows Forms GUI Thread Unresponsive

查看:74
本文介绍了Windows窗体GUI线程无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以解决这个问题的解决方案。


让我解释一下,我已经在我的系统上运行了服务,我的

应用程序接收来自这些服务的诊断消息,我想要为每个发送消息的服务创建一个MDIChild窗口。


好​​了到目前为止这么好,但是如果一个服务不断向它的窗口发送

消息,我会遇到问题,因为这个窗口非常忙于更新它的视图,因此因此因为b $ b因为它在所有其他MDIChild窗口的同一个线程和

MDIParent窗口中,整个应用程序没有响应,因为这个窗口

太忙了。


我确实设法让多线程MDI在C ++ ATL / WTL
应用程序中运行和稳定,但事实证明这至少是一种心痛。我不想再去那条路了。

另外

1)我没有同样的控制水平c#

2)在另一个帖子中有mdiparent不是一个真正的选择。


任何人都有了想法

提前致谢

Brian。

I wonder can anyone reccomment a solution to this problem.

Let me explain, I''ve services running on my system, my
application receives diagnostic messages from these services, what i want to
do is create an MDIChild window for each service that is sending messages.

Ok so far so good, but I get problems if one service is constantly sending
messages to it''s window because, this window is very busy updating it''s view,
hence because it''s in the same thread at all other MDIChild windows and the
MDIParent window the whole application is unresponsive because this window
is too busy.

I did manage to get the Multithread MDI working and stable in a C++ ATL/WTL
application but it proved a heartache to say the least. I''d rather not go
down that road again.
Also
1) I don''t have same level of control in c#
2) having mdiparent in a different thread is not really an option.

Anyone got an idea
Thanks in advance
Brian.

推荐答案

嗨Brian


你需要查看Control.Invoke / Control.BeginInvoke / Control.EndInvoke

文档 - 本质上,你应该在一个worker

线程上运行你的服务代码,然后你需要将数据封送回UI线程。如果你在
Windows窗体专栏的奇迹中看看Chris在MSDN上关于多线程的文章,那应该可以帮助你开始......(我想这就是

跟进关于在不同线程上运行表单的帖子!)


HTH


Nigel Armstrong

" Brian Keating EI9FXB"写道:
Hi Brian

You need to look at Control.Invoke/Control.BeginInvoke/Control.EndInvoke in
the documentation - essentially, you should run your service code on a worker
thread, then you need to marshal the data back onto the UI thread. If you
look at Chris Sells articles on MSDN on multithreading in the Wonders of
Windows Forms columns, that should get you started...(I guess this is the
follow up to the post about running forms on separate threads!)

HTH

Nigel Armstrong

"Brian Keating EI9FXB" wrote:
我想知道是否有人可以解决这个问题的解决方案。

让我解释一下,我已经在我的系统上运行了服务,我的
应用程序从这些服务接收诊断消息,我想要做的是为每个发送消息的服务创建一个MDIChild窗口。

好到目前为止很好,但是我遇到了问题如果一个服务不断向它的窗口发送消息,因为这个窗口非常忙于更新它的视图,因此它在所有其他MDIChild窗口的同一个线程中和/或MDIParent窗口整个应用程序没有响应,因为这个窗口太忙了。

我确实设法让多线程MDI在C ++ ATL / WTL中工作和稳定<应用程序,但至少可以说是一个心痛。我宁愿不再去那条路了。
还有
1)我没有同样的控制水平c#
2)有一个不同的mdiparent线程不是真正的选择。

任何人都有了想法
提前致谢
Brian。
I wonder can anyone reccomment a solution to this problem.

Let me explain, I''ve services running on my system, my
application receives diagnostic messages from these services, what i want to
do is create an MDIChild window for each service that is sending messages.

Ok so far so good, but I get problems if one service is constantly sending
messages to it''s window because, this window is very busy updating it''s view,
hence because it''s in the same thread at all other MDIChild windows and the
MDIParent window the whole application is unresponsive because this window
is too busy.

I did manage to get the Multithread MDI working and stable in a C++ ATL/WTL
application but it proved a heartache to say the least. I''d rather not go
down that road again.
Also
1) I don''t have same level of control in c#
2) having mdiparent in a different thread is not really an option.

Anyone got an idea
Thanks in advance
Brian.



Brian,


您的服务如何向其窗口发送消息,请详细说明。

我想您有多项服务和Windows窗体应用程序,你是否有一个后台线程监听你的服务发送的消息?

如果你这样做,你如何从这个workerthread更新UI?你是否正确使用Control.BeginInvoke对来自UI的调用进行绑定?


Willy。

" Brian Keating EI9FXB" < csharp at briankeating.net>在消息中写道

news:46 ********************************** @ microsof t.com ...
Brian,

How is your service "sending messages to it''s window", please elaborate.
I suppose you have several services and a Windows Forms application, do you
have a background thread listening for messages sent by your services?
If you do, how do you update the UI from this workerthread? Are you
correctly marhaling the calls to the UI using Control.BeginInvoke?

Willy.
"Brian Keating EI9FXB" <csharp at briankeating.net> wrote in message
news:46**********************************@microsof t.com...
我想知道是否有人可以解决这个问题的解决方案。

让我解释一下,我已经在我的系统上运行了服务,我的
应用程序接收来自这些服务的诊断消息,我想要做的就是为每个发送消息的服务创建一个MDIChild窗口。

好的,到目前为止这么好,但是如果一个服务不断地向它的窗口发送消息,我就会遇到问题,因为这个窗口非常忙于更新它的视图,因此它因为它在所有其他MDIChild窗口的同一个线程中和
MDIParent窗口整个应用程序没有响应,因为这个窗口太忙了。

我做了设法让多线程MDI在C ++
ATL / WTL
应用程序中运行和稳定,但事实证明它至少可以说是一种心痛。我宁愿不再去那条路了。
还有
1)我没有同样的控制水平c#
2)有一个不同的mdiparent线程不是真正的选择。

任何人都有了想法
提前致谢
Brian。
I wonder can anyone reccomment a solution to this problem.

Let me explain, I''ve services running on my system, my
application receives diagnostic messages from these services, what i want
to
do is create an MDIChild window for each service that is sending messages.

Ok so far so good, but I get problems if one service is constantly
sending
messages to it''s window because, this window is very busy updating it''s
view,
hence because it''s in the same thread at all other MDIChild windows and
the
MDIParent window the whole application is unresponsive because this window
is too busy.

I did manage to get the Multithread MDI working and stable in a C++
ATL/WTL
application but it proved a heartache to say the least. I''d rather not go
down that road again.
Also
1) I don''t have same level of control in c#
2) having mdiparent in a different thread is not really an option.

Anyone got an idea
Thanks in advance
Brian.



Ni Neil,


你说得对,这篇文章是对我以前的帖子的跟进。


Control.Inovke是对我来说不是一个真正的选择,它使用ThreadPool

(间接)线程池一次只能运行这么多作业,而一些

框架类在内部使用它,所以我不想用很多

的任务阻止它。

所以我会使用一种不同的方法将我的数据封送到GUI线程。


但是这不是我的问题,我的问题是我所有的Windows

(GUI窗口)都在同一个线程中运行所以如果一个窗口是获取

使用要显示的数据加载消息GUI会变得没有响应。


希望你理解我的问题,我会有一个线程(工作者)从我的Windows服务获取

消息,这个线程将发送消息到我的

MDIClient窗口,

问题是如果所有我的MDIClients在GUI上运行那么所有的

MDIClients,包括MDIParent将没有反应。


希望这会让你有点意义并感谢你的时间。

问候

Brian。

谢谢我会读一读Chris Sells。


" Nigel Armstrong"写道:
Ni Neil,

You''re quite right this post is a follow up to my previous posts.

The Control.Inovke is not really an option to me, it uses a ThreadPool
(indirectly) The thread pool can only run so many jobs at once, and some
framework classes use it internally, so I don''t want to block it with a lot
of tasks.
So I''ll use a different method of marshaling my data to the GUI thread.

However this is not really my problem, my problem is that all my Windows
(GUI windows) are running in the same thread so If one window is getting
loadsa messages with data to display then the GUI will become unresponsive.

Hope you understand my problem, I will have a thread (worker) that gets
messages from my windows services, this thread will send messages to my
MDIClient window,
problem is if all my MDIClients run on the GUI thead then all the
MDIClients, including the MDIParent will be unresponsive.

Hope this makes some bit of sence and thanks for your time.
Regards
Brian.
Thanks I''ll have a read of the Chris Sells.

"Nigel Armstrong" wrote:
嗨Brian

你需要查看文档中的Control.Invoke / Control.BeginInvoke / Control.EndInvoke - 本质上,你应该在一个worker
线程上运行你的服务代码,然后你需要将数据封送回UI线程。如果您在Windows窗体专栏的奇迹中看看Chris在MSDN上关于多线程的文章,那应该可以帮助您入门......(我想这是
跟进帖子关于在单独的线程上运行表单!)

HTH

Nigel Armstrong

Brian Keating EI9FXB写道:
Hi Brian

You need to look at Control.Invoke/Control.BeginInvoke/Control.EndInvoke in
the documentation - essentially, you should run your service code on a worker
thread, then you need to marshal the data back onto the UI thread. If you
look at Chris Sells articles on MSDN on multithreading in the Wonders of
Windows Forms columns, that should get you started...(I guess this is the
follow up to the post about running forms on separate threads!)

HTH

Nigel Armstrong

"Brian Keating EI9FXB" wrote:
我想知道是否有人可以解决这个问题的解决方案。

让我解释一下,我已经在我的系统上运行了服务,我的
应用程序从这些服务接收诊断消息,我想要做的是为每个发送消息的服务创建一个MDIChild窗口。

好到目前为止很好,但是我遇到了问题如果一个服务不断向它的窗口发送消息,因为这个窗口非常忙于更新它的视图,因此它在所有其他MDIChild窗口的同一个线程中和/或MDIParent窗口整个应用程序没有响应,因为这个窗口太忙了。

我确实设法让多线程MDI在C ++ ATL / WTL中工作和稳定<应用程序,但至少可以说是一个心痛。我宁愿不再去那条路了。
还有
1)我没有同样的控制水平c#
2)有一个不同的mdiparent线程不是真正的选择。

任何人都有了想法
提前致谢
Brian。
I wonder can anyone reccomment a solution to this problem.

Let me explain, I''ve services running on my system, my
application receives diagnostic messages from these services, what i want to
do is create an MDIChild window for each service that is sending messages.

Ok so far so good, but I get problems if one service is constantly sending
messages to it''s window because, this window is very busy updating it''s view,
hence because it''s in the same thread at all other MDIChild windows and the
MDIParent window the whole application is unresponsive because this window
is too busy.

I did manage to get the Multithread MDI working and stable in a C++ ATL/WTL
application but it proved a heartache to say the least. I''d rather not go
down that road again.
Also
1) I don''t have same level of control in c#
2) having mdiparent in a different thread is not really an option.

Anyone got an idea
Thanks in advance
Brian.



这篇关于Windows窗体GUI线程无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆