如何阻止的WinForms用户界面,而后台线程运行 [英] How to block Winforms UI while background thread is running

查看:152
本文介绍了如何阻止的WinForms用户界面,而后台线程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个WinForms应用程序,做了很多长时间运行的调用到从UI线程的应用程序服务器,所以用户界面保持反应迟钝,无法使用,不可关闭了一段时间。 (这让我真正去 AAAAAAAAARGH!

I've inherited a Winforms application that does a lot of long running calls into the application server from the UI thread, so the UI stays unresponsive, unusable, unclosable for quite some time. (Which makes me really go AAAAAAAAARGH!)

我打算在服务器调用后台线程,并在UI禁用移动 - 但移动和放大器;可关闭的 - 而后台线程执行其工作

I plan to move the server calls to a background thread and have the UI disabled - but movable & closable - while the background thread does its work.

那么,这将是抑制用户输入我的应用程序的最佳方法是什么?我沿着模式的进度对话框的思路思考,但我preFER不强迫我扔的视觉效果到用户的脸部溶液(一些服务器运行在不到500毫秒这样一个对话框运行是的没有的最佳...)

So what would be the best way to inhibit user input to my application? I'm thinking along the lines of "modal progress dialog", but I'd prefer a solution that does not force me to throw visuals into the face of the user (some server operations run within less than 500ms so a dialog is not optimal ...)

有没有办法在的WinForms,以prevent发动行动或改变数据的应用程序,同时通过一些特定的事情(调整大小,显示,隐藏和家人,并关闭窗口的用户)让用户?我想preFER的方式,并不让我访问我的形式每一个用户界面元素,并将其设置为禁用...有不少人在该应用确实有一个黑客在UI设计师,直到它显示源$ C ​​$ C华而不实的东西的风格。重构每一个臭的东西,直到发布日期没办法......

Is there any way in Winforms to prevent the user from launching actions or changing data in the application while letting through a few select things (resize, show, hide and family and the user closing the window)? I'd prefer a way that does not make me access every UI element in my forms and set it to disabled ... there are quite a lot of them and that application really has a "hacked in the UI designer until it shows flashy things" style of source code. No way of refactoring EVERY smelly thing until release date ...

哦,对了,这个应用程序住在.NET框架2

Oh, by the way, this App lives in .net framework 2

推荐答案

我知道的唯一方法就是得到一些/所有控件为禁用。然而,这取决于如何进行控制的摆出来,就没有必要设置每一个控制为禁用 - 当一个容器控件被禁用,那么它的所有孩子都是残疾人,太。例如,如果你有一个分组框有一些控制,如果你设置了分组框来禁用,那么所有的内部控制分组框将被禁用了。

The only way I know of is to get some/all controls as disabled. However, depending on how the controls are laid out, it isn't necessary to set every control as disabled - when a container control is disabled, then all of its children are disabled, too. For example, if you have a GroupBox with some controls, if you set the GroupBox to disabled, then all of the controls within the GroupBox will be disabled, too.

这篇关于如何阻止的WinForms用户界面,而后台线程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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