本文介绍了Form.Invoke冻结UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索周围约一小时,我仍然没有找到任何解决方案。

I have been googling around for about an hour, and I still don't found any solution.

我只是尝试设置从另一个线程进度的最大值。于是我找到了Control.Invoke方法。我已经去进取,实现它:

I simply try to set the maximum value of a progressbar from another thread. So I found the Control.Invoke method. I've been going ahead and implement it:

现在,当我调试我的应用程序它只是stucks在 this.Invoke 行。用户界面出现,它被冻结。所以,我去进取,谷歌表示出来,并告诉我使用 this.BeginInvoke()。我实现它,我很好,用户界面​​不冻结。那安静的不错,但其实我的进度条的最大值并没有改变:(

Now, when I debug my App it simply stucks at the this.Invoke line. The UI comes up, and it is frozen. So I was going ahead and google that out, and it told me to use this.BeginInvoke(). I implemented it, and I was fine, the UI don't freeze.Thats quiet nice, but in fact the maximum value of my progress bar didn't change :(

我是什么做错了吗?

编辑:也许可以帮助:我使用 Parallel.Invoke(); 来管理我的线程...

Maybe that helps: I am using Parallel.Invoke(); to manage my thread ...

推荐答案

Control.Invoke 将只有当它被称为一个工作线程和UI线程块被阻止

Control.Invoke will only block when it is called on a worker thread and the UI thread is blocked.

您发布的code是正确的。您必须阻塞UI线程别的地方。

The code you posted is correct. You must be blocking the UI thread somewhere else.

这篇关于Form.Invoke冻结UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 00:13