Backgroundworker和ProgressBar帮助! [英] Backgroundworker and ProgressBar help!

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

问题描述

你好,早上好!我一直在研究一个应用程序,它从SQL数据库加载数据。一切都已完成,但我的用户已请求我添加进度条,以便她知道它是否挂起以及是否仍处理/下载)。



我已经从CodeProject完成了一个非常有用的教程,帮助了很多。但我的问题是当我点击我的btnReloadTableData(重装数据按钮)时如何启动进度条/工作人员?



这是教程我找到并解释背景工作者和进度条的不同部分非常有帮助。



链接 DaveyM69发表



我试过放置InitializeComponent()下面的代码;但没有进展到该项目。有人可以帮帮我吗?基本上我可能不完全理解调用哪个方法以及将它放在我的btn_click方法的哪个位置。

Hello and good morning all! I've been working on an application and it loads data from a SQL database. All is finished but my user has requested that I add a progress bar so she knows if it hangs and if it is still processing/downloading).

I have completed a very useful tutorial from CodeProject that helped out a lot. But my question is How do I initiate the progressbar/worker when I click my btnReloadTableData (reload data button)?

Here is the tutorial I found and it is extremely helpful explaining the different pieces of the background worker and progress bar.

Link DaveyM69 posted

I have tried placing the code from below InitializeComponent(); but with no progress to the project. Can someone please help me? Basically I might not fully understand which method to call and where to place it on my btn_click method.

推荐答案

只要你在Shown方法中执行了代码:

As long as you have executed the code in the Shown method:
void Form1_Shown(object sender, EventArgs e)
{
    // Start the background worker
    backgroundWorker1.RunWorkerAsync();
}



工作人员应该运行,并以1/10秒的间隔发出进度标记 - 因此完成后台任务需要10秒钟。 br />


所以:使用调试器,并输入断点来检查发生了什么:

是否正在调用RunWorkerAsync?

工人正在运行吗?

进度事件是否正在执行?



如果答案是肯定的,那么我们需要更多关于具体情况的详细信息。


The worker should run, and issue progress markers at 1/10th second intervals -- so it will take 10 seconds to finish the background task.

So: use the debugger, and put breakpoints in to check what is going on:
Is the RunWorkerAsync being called?
Is the worker running?
Is the progress event executing?

If the answer is yes to all these, then we would need more details on exactly what is happening.


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

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