在數學所以這裏不強是我的問題:更新進度與適當的值
我用一個進度條來顯示在後臺執行工作的進展情況:
片段我的代碼:
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我想要你PDATE它同時做適當的值從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;
}
任何幫助,不勝感激:
這ISN」與答案相關 - 你確定你正在使用動態c orrectly? – Jason 2012-02-26 02:18:31
是的動態工作正常,我有我需要的所有值 – 2012-02-26 02:20:37