已完成的WorkItem列表未填充

时间:2015-02-24 05:33:43

标签: c# .net queue backgroundworker

我有一个程序,我们在队列中安排工作项并逐个处理后台线程并将完成的工作项加载到列表中。

以下是安排工作项目的代码。

Queue<string> workitems = new Queue<string>();
List<string> completeditems = new List<string>();
string work = string.Empty;

private void pushBtn_Click(object sender, EventArgs e)
{
        workitems.Enqueue(work.ToString());

        todoList.DataSource = workitems.ToList();

        ProcessNextWorkItem(); // Method responsible to Dequeue work item and hand it over to background thread, if background thread is not busy.
}

下面是处理BackgroundWorker的RunWorkCompletedEvent的代码。

private void RunWorkCompletedEvent(object sender_, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs_)
{
        completeditems.Add(work.ToString);
        completedList.DataSource = completeditems;

        ProcessNextWorkItem(); // Method responsible to Dequeue next work item, if any, and hand it over to background thread, if background thread is not busy.
}

由于某些未知原因,已完成的工作项列表框始终只有第一个已完成的工作项。我在这里错过了什么吗?

0 个答案:

没有答案