【发布时间】:2013-12-27 00:29:01
【问题描述】:
我的应用程序向CheckedListBox 中的选定组发送消息。我想在程序发送消息时使用Progressbar。
foreach (object item in checkedListBox1.CheckedItems)
{
if (item.ToString() == gi.name) //don't read
{
if (txtBoxPath.Text == string.Empty) //don't read
{
try
{
Dictionary<string, object> args = new Dictionary<string, object>();
args["message"] = txtBoxStatus.Text;
fb.Post(gi.id + "/feed", args);
sCount = checkedListBox1.CheckedItems.Count;
for (int i = 0; i < sCount; i++)
{
backgroundWrkSendPOST.ReportProgress(100 / sCount); //****HERE****
}
}
catch (FacebookApiException ex)
{
MessageBox.Show("ERRO:" + Environment.NewLine + ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
.......
其中:sCount(int):表示选中列表框中选中项的数量。 因此,遵循数学规则,对于选择的每个项目 {y}(foreach 函数中的项目)应该乘以 100% / {y},这意味着最终应该是 100%。但是似乎foreach函数不读取后台工作,并且不相乘。
我们调试时的输出:
有人可以帮助我吗?最后,这个进度条应该保持在 100%。
【问题讨论】:
标签: c# multithreading foreach progress-bar backgroundworker