我如何构建简单进度栏? [英] How Can i build Simple Progress Bar?

查看:60
本文介绍了我如何构建简单进度栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要创建一个简单的进度条,该进度条将演示一个简单过程的进度,如下所示:

Suppose that i Want to Create a simple progress bar which will demonstrate the progress for a simple process like the following:

int s=0;
while(s<10000)
{
s++;
}

//and if the process Like this one:

string sequence="ATCGACAGCAGAC";

string AminoAcid = MainOperation.DNA_To_AminoAcid(sequence);

//Or Like this:

string Files_In_Directories=MainOperation.GetFiles("F:\");



谢谢您的关注.



thank you for your concern

推荐答案

解决此问题的标准方法是使用标准(WinForms?WPF?)进度栏.在单独的线程中启动冗长的操作(使用Thread.Start,BackgroundWorkerThread或Task,在该操作上发出进度事件的信号,并让UI类(可能是您的主窗体)订阅进度事件以更新进度栏.将在操作线程上引发,您将需要使用Invoke或BeginInvoke将对进度条控件的更新封送回UI线程.
The standard approach to this is to use the standard (WinForms? WPF?) progress bar. Start the lengthy operation in a separate thread (using Thread.Start, BackgroundWorkerThread or Task, signal progress events on the operation, and have the UI class (probably your main form) subscribe to the progress event to update the progress bar. Since the event will be raised on the operation thread, you will need to use Invoke or BeginInvoke to marshal the update to the progress bar control back to the UI thread.


这篇关于我如何构建简单进度栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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