在C#Winforms中使用多线程的响应式GUI [英] Responsive GUI using Multi-threading in C# Winforms

查看:99
本文介绍了在C#Winforms中使用多线程的响应式GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请中有一个子表格.该表格有大约50多个组合框,每个人都从数据库中获取数据.所有combobex都在表单的load事件中加载.数据很大.数据检索大约需要2分钟.当我打开此表单时,我的整个应用程序变得无响应.该应用程序挂起,大约2分钟后便恢复运行:/

I have a child form in my application. This form has got about more than 50 comboboxes and everyone is getting data from database. All combobexs are loaded in the load event of the form. The data is large. Data retrieval takes about 2 minutes. when I open this form, my whole application becomes unresponsive. The application hangs and it gets life after about 2 minutes :/

正如我所研究的,我们可以使用不同的线程来避免这种情况.有人可以指导实现多线程的安全性和安全性,以使我的应用程序响应吗?

As I have studied, we can use different threads in order to avoid such situations. Can someone guide, is it possible, safe and secure to implement multi-threading in order to make my application responsive?

请指导我,并在可能的情况下编写示例代码,说明多线程在c#中的工作方式.您可以简单地解释使用带有gridview的表单,该表单在单独的线程中将数据表作为daTASOURCE接收,并且GUI即使在数据库中花费的时间也很长,...有任何帮助.不胜感激.

Please guide me and write a sample code if possible how multithreading works in c#. You can simply explain using a form having a gridview that takes datatable as daTASOURCE in a separate thread and GUI is responsive even database takes too much time...Any help is appreciated.Thanx in advance!

推荐答案

看看

Take a look at the BackgroundWorker class. This can do exactly what you want. You can also include something like a progress bar to show users the data is still being loaded before they go ahead and do stuff in your child form.

这篇关于在C#Winforms中使用多线程的响应式GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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