0

我正在使用 Microsoft.ConfigurationManagement.Messaging 包来使用 BITS。到目前为止,我已经编写了以下代码:

BitsJob job = new BitsJob(BitsJobType.Download, displayName);
BitsJobState jobState;
job.AddFileToJob(new Uri(source), destination); // source & destination are method parameters
job.Resume();
do
{
    // Do something with the job as long as its transferring
} while (/*Get job state here*/);

现在我想在 do-while-statement 中检索作业的状态。我找不到BitsJob返回作业当前状态的实例的属性或方法。有人可以告诉我如何获得当前的工作状态吗?

4

1 回答 1

0

自己想出了答案。对于所有徘徊在这个问题上的人。BitsJobProgress最好的方法是使用事件来检索它。以下代码示例可以表明

Job.BitsJobProgress += (sender, e) => 
{
    JobState = e.JobState;
};

包括BitsJobEventArgs作业状态。这样就可以检索它并将其保存在变量中。

于 2020-07-08T07:52:06.297 回答