Csharp Windows表单 [英] Csharp windows forms

查看:319
本文介绍了Csharp Windows表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是创建一个允许字段更新而无需用户交互的表单.

如果您有表单的按钮.没问题,标签可以更新.如果应用程序在没有用户交互的情况下启动作业,则标签不会更新.

您是否将其穿线,但是在何处或如何构建表格?

谢谢dave

problem to create a form that allow fields to updated , without user interaction.

If you have a button of the form. No problem the label can be updated. If the application start the job without user interaction the label is not updated.

Do you thread it but where or how you do build the form?

thanks dave

推荐答案

不更新控件的主要原因是因为您的代码100%忙于做某事.

如果您的应用程序正在执行CPU密集型任务,并希望定期更新UI,则最佳选择是使用 ^ ]

您将在另一个线程中执行CPU密集型代码,并或多或少定期向主线程报告进度.

您可以调用ReportProgress报告进度百分比,如果需要的话,还可以提供更多信息.

首先,从工具箱中将BackgroundWorker拖放到窗体上,并调整其属性并实现适当的事件处理程序.

最后要注意的是,您要经常调用ReportProgress,以使UI能够显示当前状态.如果有进度条,则每1%的报告进度是一个好的开始.

如果您过于频繁地报告进度,那么将会有一些开销,并且在最坏的情况下,实际工作可能会在UI完成之前完成很多.

通常,找到合适的中间位置并不难.
The main reason why a control is not updated would be because your code is 100% busy doing something.

If you application is performing CPU intensive task and want to update the UI regulary, the best option is to use a BackgroungWorker[^]

You will the do the CPU intensive code in another thread and more or less regulary report progress to the main thread.

You would call ReportProgress to report the progress percentage and if desired some more information.

You start by dropping a BackgroundWorker from the toolbox onto your form and adjust its property and implement appropriate events handler.

The final thing to be aware is that you want to call ReportProgress often enough for you UI to display the current state. If you have a progress bar, the reporting progress every 1% is a good start.

If you report progress too often, then there would be some overhead and in the worst case, the actual work might be completed a lot before the UI has completed.

Generally it is not that hard to find a right middle.


是的,我想就是这样.

我想开始工作并观察状态,而无需进行任何交互.

非常感谢
Yes I think this is it.

I want to kick off a job and watch the status with no interaction.

Thank you very much


这篇关于Csharp Windows表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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