【发布时间】:2012-02-26 02:15:33
【问题描述】:
数学不强所以这是我的问题:
我正在使用进度条来显示在后台执行的工作进度:
我的代码片段:
int i = 0;
int totalFriends = 0;
foreach (dynamic friend in facebookFriends)
{
totalFriends++;
}
foreach (dynamic friend in facebookFriends)
{
i++;
var friend = new FacebookFriend
{
FbId = friend["uid"].ToString()
};
AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
}
现在应用程序做的远不止这些,在这里我只执行一小部分工作: 因此,例如,在我到达本节之前,进度条的值为 7,在执行工作后它必须达到 20,我想在使用从 7 到 20 的适当值进行工作时更新它:
我对此的看法如下:
var intiProgressbarValue = 7;
var finalProgressbarvalue = 20;
foreach (dynamic friend in facebookFriends)
{
i++;
var friend = new FacebookFriend
{
FbId = friend["uid"].ToString()
};
AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
var calculatedValue = CalculatedValue(initProgressbarValue, finalProgressBarValue,totalFriends, i);
UpdateProgressBar( calculatedValue);
}
//note that totalFriends can be any number lets say from 0 to 5000
private int CalculatedValue(int initVal, int finalVal, int totalFriends, int currentFriend)
{
int progressBarVal = 0;
//**
Perform logic so it will return a progress value that is bigger that 7 and smaller that 20 depending on the number of friends and currently updated friend
**//
progressBarVal = 8;//this would be the result of calculation, a value from 8 to 20
return progressBarVal;
}
非常感谢任何帮助:
【问题讨论】:
-
这与答案无关 - 你确定你正确使用了动态吗?
-
是的,动态效果很好,我有我需要的所有值
标签: c# progress-bar backgroundworker