WinForms的异步进度对话框 [英] Asynchronous Progress Dialog for WinForms

查看:88
本文介绍了WinForms的异步进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的项目中使用:



用于WinForms的AJAX风格的异步进度对话框 [ ^ ]



我不知道怎么用这在我的项目中,



例如:



在按钮事件中点击我使用:



I try to use in my project:

AJAX-style Asynchronous Progress Dialog for WinForms[^]

I don''t know how to use this in my project,

for example:

In a button event click i use:

winProgresIncarcare.AsyncProcessDelegate method = delegate
            {
                string NumeClientCautat = txtCautaDupaNume.Text;
                this.sClienti.DataSource = SetariAmanet.TotiClienti(NumeClientCautat);
            };
            RunAsyncOperation(method);





进度圈出现在我的表格上,但是扔了一个例外





the progress circle appear on my form but trow an exception

Cross-thread operation not valid: Control 'dVizualizareClienti' accessed from a thread other than the thread it was created on.





有关如何在同一个线程中转换代码的任何建议吗?



any suggestions how to transform my code in the same thread?

推荐答案

你最好问一下这篇文章的作者。加载包含文章的页面,找到评论和讨论部分,单击添加评论或问题并提出您的问题。作者将收到通知并有机会回复。



-SA
You should better ask the author of this article. Load the page with the article, locate the section "Comments and Discussions", click "Add a Comment or Question" and ask your question. The author will get a notification and a chance to reply.

—SA


在这里有关如何解决UI线程的跨线程问题的一些信息:



您无法从非UI线程调用与UI相关的任何内容。相反,您需要使用 Invoke System.Windows.Threading的方法。 Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表单)。



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

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

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



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

如何让keydown事件在不同的操作上运行vb.net中的线程 [ ^ ],

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



我不知道文章的作者是否没有妥善处理,或者这是你的错,但这是UI开发的一个基本问题,每个开发人员应该非常清楚。



-SA
And here some information for you on how to resolve the cross-threading issues with the UI thread:

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[^].

I don''t know if the author of the article did not properly take care of that, or if it is your fault, but this is one fundamental issue of UI development every developer should know very well.

—SA


这篇关于WinForms的异步进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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