如何让进度条的更新速度不够快? [英] How can I make the progress bar update fast enough?
问题描述
我用一个进度条来显示用户有多远沿着过程。它有17个步骤,它可以在任何地方从约5秒至两三分钟,这取决于天气(当然,数据库)
我有这个在XP没有问题,进度条了罚款,但在Vista中测试时,我发现,它已不再是这种情况。
例如:如果需要接近5秒,它的也许的消失,因为它完成之前,通过使1/3的方式。即使它的进步是在17 17,它并没有表现出来。我相信这是动画的,因为Vista对进度条和动画无法完成足够快。
有谁知道我怎么能解决这个?
下面是code:
这是更新进度条的一部分,等待是有进度条的形式。
INT进度= 1;
// 1现金收款项目
waiting.setProgress(进度,18,进步,现金收款项目);
tblCashReceiptsApplyToTableAdapter1.Fill(rentalEaseDataSet1.tblCashReceiptsApplyTo);
进度++;
// 2现金收入
waiting.setProgress(进步,现金收入);
tblCashReceiptsTableAdapter1.Fill(rentalEaseDataSet1.tblCashReceipts);
进度++;
// 3支票簿codeS
waiting.setProgress(进步,支票簿codeS);
tblCheckbook codeTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbook code);
进度++;
// 4支票簿项
waiting.setProgress(进步,支票簿项);
tblCheckbookEntryTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbookEntry);
进度++;
// 5支票簿
waiting.setProgress(进步,支票簿);
tblCheckbookTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbook);
进度++;
// 6公司
waiting.setProgress(进步,公司);
tblCompanyTableAdapter1.Fill(rentalEaseDataSet1.tblCompany);
进度++;
// 7费用
waiting.setProgress(进步,费用);
tblExpenseTableAdapter1.Fill(rentalEaseDataSet1.tblExpense);
进度++;
// 8收入
waiting.setProgress(进步,收入);
tblIncomeTableAdapter1.Fill(rentalEaseDataSet1.tblIncome);
进度++;
// 9属性
waiting.setProgress(进步,属性);
tblPropertyTableAdapter1.Fill(rentalEaseDataSet1.tblProperty);
进度++;
// 10租住单位
waiting.setProgress(进度,租赁单位);
tblRentalUnitTableAdapter1.Fill(rentalEaseDataSet1.tblRentalUnit);
进度++;
// 11租户状态值
waiting.setProgress(进步,租客状态值);
tblTenantStatusTableAdapter1.Fill(rentalEaseDataSet1.tblTenantStatus);
进度++;
// 12租户
waiting.setProgress(进步,租客);
tblTenantTableAdapter1.Fill(rentalEaseDataSet1.tblTenant);
进度++;
// 13租户交易codeS
waiting.setProgress(进步,租客事务codeS);
tblTenantTrans codeTableAdapter1.Fill(rentalEaseDataSet1.tblTenantTrans code);
进度++;
// 14交易
waiting.setProgress(进步,交易);
tblTransactionTableAdapter1.Fill(rentalEaseDataSet1.tblTransaction);
进度++;
// 15供应商
waiting.setProgress(进步,卖方);
tblVendorTableAdapter1.Fill(rentalEaseDataSet1.tblVendor);
进度++;
// 16工作订单分类
waiting.setProgress(进步,工单类别);
tblWorkOrderCategoryTableAdapter1.Fill(rentalEaseDataSet1.tblWorkOrderCategory);
进度++;
// 17工作订单
waiting.setProgress(进步,工作单);
tblWorkOrderTableAdapter1.Fill(rentalEaseDataSet1.tblWorkOrder);
进度++;
// 18存储特效
waiting.setProgress(进步,存储过程);
getAllCheckbookBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetAllCheckbookBalances);
getAllTenantBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetAllTenantBalances);
// getCheckbookBalanceTableAdapter1;
// getTenantBalanceTableAdapter1;
getTenantStatusID_CurrentTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Current);
getTenantStatusID_FutureTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Future);
getTenantStatusID_PastTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Past);
selectVacantRentalUnitsByIDTableAdapter1.Fill(rentalEaseDataSet1.SelectVacantRentalUnitsByID);
getRentBasedBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetRentBasedBalances);
getAgingBalanceTableAdapter2.Fill(rentalEaseDataSet1.GetAgingBalance);
waiting.Close();
下面是等待的形式:
公共部分类PleaseWaitDialog:表格{
公共PleaseWaitDialog(){
CheckForIllegalCrossThreadCalls = FALSE;
的InitializeComponent();
}
公共无效setProgress(INT当前,INT最大,INT分钟,串loadItem){
Debug.Assert的(分钟< =最大,最小是大于最大!);
Debug.Assert的(当前> =分钟,目前的进展是小于最小进展!);
Debug.Assert的(电流I =最大,的进展是大于最大进步!);
prgLoad.Minimum =分钟;
prgLoad.Maximum = MAX;
prgLoad.Value =电流;
lblLoadItem.Text = loadItem;
}
公共无效setProgress(INT当前,串loadItem){
this.setProgress(目前,prgLoad.Maximum,prgLoad.Minimum,loadItem);
}
}
尝试调用调用 waiting.setProgess()
的方法,因为等待
似乎生活在另一个线程,这将是一个的经典跨线程调用(编译器警告您,如果你让他)。
由于 Control.Invoke
是一个有点笨拙用我通常使用的扩展方法,让我通过一个lambda EX pression:
waiting.ThreadSafeInvoke(()=> waiting.setProgress(...));
//也看到http://stackoverflow.com/questions/788828/invoke-from-different-thread
公共静态类ControlExtension
{
公共静态无效ThreadSafeInvoke(该控制的控制,MethodInvoker法)
{
如果(控制!= NULL)
{
如果(control.InvokeRequired)
{
control.Invoke(法);
}
其他
{
method.Invoke();
}
}
}
}
I'm using a progress bar to show the user how far along the process is. It has 17 steps, and it can take anywhere from ~5 seconds to two or three minutes depending on the weather (well, database)
I had no problem with this in XP, the progress bar went fine, but when testing it in vista I found that it is no longer the case.
For example: if it takes closer to 5 seconds, it might make it a 1/3 of the way through before disappearing because it's completed. Even though it's progress is at 17 of 17, it doesn't show it. I believe this is because of the animation Vista imposes on progress bars and the animation cannot finish fast enough.
Does anyone know how I can correct this?
Here is the code:
This is the part that updates the progress bar, waiting is the form that has the progress bar.
int progress = 1;
//1 Cash Receipt Items
waiting.setProgress(progress, 18, progress, "Cash Receipt Items");
tblCashReceiptsApplyToTableAdapter1.Fill(rentalEaseDataSet1.tblCashReceiptsApplyTo);
progress++;
//2 Cash Receipts
waiting.setProgress(progress, "Cash Receipts");
tblCashReceiptsTableAdapter1.Fill(rentalEaseDataSet1.tblCashReceipts);
progress++;
//3 Checkbook Codes
waiting.setProgress(progress, "Checkbook Codes");
tblCheckbookCodeTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbookCode);
progress++;
//4 Checkbook Entries
waiting.setProgress(progress, "Checkbook Entries");
tblCheckbookEntryTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbookEntry);
progress++;
//5 Checkbooks
waiting.setProgress(progress, "Checkbooks");
tblCheckbookTableAdapter1.Fill(rentalEaseDataSet1.tblCheckbook);
progress++;
//6 Companies
waiting.setProgress(progress, "Companies");
tblCompanyTableAdapter1.Fill(rentalEaseDataSet1.tblCompany);
progress++;
//7 Expenses
waiting.setProgress(progress, "Expenses");
tblExpenseTableAdapter1.Fill(rentalEaseDataSet1.tblExpense);
progress++;
//8 Incomes
waiting.setProgress(progress, "Incomes");
tblIncomeTableAdapter1.Fill(rentalEaseDataSet1.tblIncome);
progress++;
//9 Properties
waiting.setProgress(progress, "Properties");
tblPropertyTableAdapter1.Fill(rentalEaseDataSet1.tblProperty);
progress++;
//10 Rental Units
waiting.setProgress(progress, "Rental Units");
tblRentalUnitTableAdapter1.Fill(rentalEaseDataSet1.tblRentalUnit);
progress++;
//11 Tenant Status Values
waiting.setProgress(progress, "Tenant Status Values");
tblTenantStatusTableAdapter1.Fill(rentalEaseDataSet1.tblTenantStatus);
progress++;
//12 Tenants
waiting.setProgress(progress, "Tenants");
tblTenantTableAdapter1.Fill(rentalEaseDataSet1.tblTenant);
progress++;
//13 Tenant Transaction Codes
waiting.setProgress(progress, "Tenant Transaction Codes");
tblTenantTransCodeTableAdapter1.Fill(rentalEaseDataSet1.tblTenantTransCode);
progress++;
//14 Transactions
waiting.setProgress(progress, "Transactions");
tblTransactionTableAdapter1.Fill(rentalEaseDataSet1.tblTransaction);
progress++;
//15 Vendors
waiting.setProgress(progress, "Vendors");
tblVendorTableAdapter1.Fill(rentalEaseDataSet1.tblVendor);
progress++;
//16 Work Order Categories
waiting.setProgress(progress, "Work Order Categories");
tblWorkOrderCategoryTableAdapter1.Fill(rentalEaseDataSet1.tblWorkOrderCategory);
progress++;
//17 Work Orders
waiting.setProgress(progress, "Work Orders");
tblWorkOrderTableAdapter1.Fill(rentalEaseDataSet1.tblWorkOrder);
progress++;
//18 Stored procs
waiting.setProgress(progress, "Stored Procedures");
getAllCheckbookBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetAllCheckbookBalances);
getAllTenantBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetAllTenantBalances);
//getCheckbookBalanceTableAdapter1;
//getTenantBalanceTableAdapter1;
getTenantStatusID_CurrentTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Current);
getTenantStatusID_FutureTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Future);
getTenantStatusID_PastTableAdapter1.Fill(rentalEaseDataSet1.GetTenantStatusID_Past);
selectVacantRentalUnitsByIDTableAdapter1.Fill(rentalEaseDataSet1.SelectVacantRentalUnitsByID);
getRentBasedBalancesTableAdapter1.Fill(rentalEaseDataSet1.GetRentBasedBalances);
getAgingBalanceTableAdapter2.Fill(rentalEaseDataSet1.GetAgingBalance);
waiting.Close();
Here is the waiting form:
public partial class PleaseWaitDialog : Form {
public PleaseWaitDialog() {
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
public void setProgress(int current, int max, int min, string loadItem) {
Debug.Assert(min <= max, "Minimum is bigger than the maximum!");
Debug.Assert(current >= min, "The current progress is less than the minimum progress!");
Debug.Assert(current <= max, "The progress is greater than the maximum progress!");
prgLoad.Minimum = min;
prgLoad.Maximum = max;
prgLoad.Value = current;
lblLoadItem.Text = loadItem;
}
public void setProgress(int current, string loadItem) {
this.setProgress(current, prgLoad.Maximum, prgLoad.Minimum, loadItem);
}
}
Try invoking the call to the waiting.setProgess()
method since waiting
seems to live in another thread and this would be a classic cross thread call (which the compiler warns you about if you let him).
Since Control.Invoke
is a bit clumsy to use I usually use an extension method that allows me to pass a lambda expression:
waiting.ThreadSafeInvoke(() => waiting.setProgress(...));
.
// also see http://stackoverflow.com/questions/788828/invoke-from-different-thread
public static class ControlExtension
{
public static void ThreadSafeInvoke(this Control control, MethodInvoker method)
{
if (control != null)
{
if (control.InvokeRequired)
{
control.Invoke(method);
}
else
{
method.Invoke();
}
}
}
}
这篇关于如何让进度条的更新速度不够快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!