c#listbox帮助需要 [英] c# listbox help need

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

问题描述

您好b $ b

我在c#winform中使用了一个列表框。

i想要在执行按钮点击的过程中显示我在列表框中添加的所有行。

按钮点击事件需要大约8 - 10秒才能完成工作

并添加大约(300 + -30)行我从3 webservice获取数据。

i从第一个服务获得并且我在列表框中添加,然后我从sec服务添加到列表框和最后一个服务我添加到列表框。



知道我想及时显示他们实时添加的行。不要等到点击按钮的事件结束。

可以有人建议我怎么做吗?



抱歉我的糟糕的英语。

Hi
i am using a listbox in c# winform.
i wanna to display all rows i add in listbox in moment the event button click is executed.
the event of button click need around 8 - 10 sec to finish the work
and add around (300 +-30) rows i get the data from 3 webservice.
i get from first service and i add in listbox, then i get from sec service add to listbox and last service i add to listbox.

know i wanna show the rows in time they are add real time. not to wait till the the event of button click is finished.
can some one suggest me how to do it?

sorry for my bad english.

推荐答案

如果您的操作有些慢但希望始终保持UI响应,您当然需要在单独的非UI中执行此类操作线程。



但是,如何使用新的数据或任何东西从非UI线程更新UI线程。问题是:你不能从非UI线程调用与UI相关的任何东西。



相反,你需要使用方法调用 BeginInvoke of System.Windows.Threading.Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表格)。



您将找到有关其工作原理的详细说明。我过去的答案中的代码示例:

Control.Invoke ()与Control.BeginInvoke() [ ^ ],

Treeview扫描仪和MD5的问题 [ ^ ]。



另请参阅有关线程的更多参考资料:

如何在vb中的其他线程上运行keydown事件。净 [ ^ ],

在启用禁用+多线程后控制事件未触发 [ ^ ]。



-SA
If you have some slow operation but want to keep UI responsive at all times, you certainly need to do such operations in a separate, non-UI thread.

However, how to update the UI thread with new data or anything, from a non-UI thread. The trouble is: you cannot call anything related to UI from non-UI thread.

Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


HI,



您可以在控件中设置自动刷新功能。这将自动定期刷新,您的数据将被刷新。请参考以下链接:



刷新窗体,即使不是活动窗口



设置刷新数据的时间并获取来自数据库的最新数据。 HOpe这将解决您的问题。



谢谢


You can set the auto refresh like thing in your control. This will be refreshed periodically automatically and your data will be refreshed. Refer the following link:

Refresh a windows form, even when not the active window

Set the time for refreshment of the data and get the latest data from the database. HOpe this will resolve your problem.

Thanks


这篇关于c#listbox帮助需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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