由于我的数学能力有限,因此我面临的问题是:
我正在使用进度条来显示后台执行工作的进度:
以下是我的代码片段:
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更新它:
我的想法是:
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;
}
非常感谢您的帮助:
非常感激您的协助: