在Windows窗体异步执行 [英] Asynchronous Execution in windows forms

查看:121
本文介绍了在Windows窗体异步执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我书面方式一个Windows窗体在上的一个按钮点击执行了大量的长期运行的程序,C#应用程序。这使GUI冻结,直到执行。此外,在执行过程中,我记录的信息和放大器;状态到列表框。然而,直到执行完成,状态是没有得到在列表框中更新。我应该如何代码,这样的状态是越来越在列表框中的执行和使GUI不冻结更新并行。

I'm writting a Windows Forms application in C# that executes a lot of long-running procedures on a single button click. This make the GUI to freeze till the execution. Also, during the execution, i'm logging the information & status to a List Box. However, untill the execution is complete, the status is not getting updated in the list box. How should i code so that the status is getting updated in list box in parallel with the execution and so that the GUI doesn't freeze.

我是新来穿线。能否请您给的这个是怎么做了一些例子吗?

I'm new to threading. Can you please give some example of how this is done?

在此先感谢您的帮助。

推荐答案

最简单而有效的方式来处理这些场景,是使用的BackgroundWorker

The simplest yet efficient way to handle these scenarios, is to use a BackgroundWorker.

您把您的重码在DoWork的事件处理程序,并更新通过ProgressChanged事件处理程序的GUI。

You put your heavy code in the DoWork event handler, and update your GUI through the ProgressChanged event handler.

您可以找到一个教程的这里结果
或更好,他们做了一个如何在的 MSDN 结果
如果你看完后更具体的问题,我会很乐意效劳。

You can find a tutorial here
Or even better they made a "how to" at msdn
If you have more specific questions after reading it, i'll be happy to oblige.

这篇关于在Windows窗体异步执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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