本文整理汇总了C#中Task.IsTaskActive方法的典型用法代码示例。如果您正苦于以下问题:C# Task.IsTaskActive方法的具体用法?C# Task.IsTaskActive怎么用?C# Task.IsTaskActive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.IsTaskActive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: waitForTask
private Task waitForTask(Task task)
{
Console.WriteLine(String.Format("Task status: {0}", task.Status));
while (task.IsTaskActive())
{
// Note: it's recommended that your application waits
// at least 2 seconds before making the first getTaskStatus request
// and also between such requests for the same task.
// Making requests more often will not improve your application performance.
// Note: if your application queues several files and waits for them
// it's recommended that you use listFinishedTasks instead (which is described
// at http://ocrsdk.com/documentation/apireference/listFinishedTasks/).
System.Threading.Thread.Sleep(5000);
task = restClient.GetTaskStatus(task.Id);
Console.WriteLine(String.Format("Task status: {0}", task.Status));
}
return task;
}
示例2: waitAndDownload
/// <summary>
/// Wait until task finishes and download result
/// </summary>
private void waitAndDownload(Task task, string outputFilePath)
{
while (task.IsTaskActive())
{
task = restClient.GetTaskStatus(task.Id);
if (!Task.IsTaskActive(task.Status))
break;
Console.WriteLine("Waiting..");
System.Threading.Thread.Sleep(1000);
}
if (task.Status == TaskStatus.Completed)
{
Console.WriteLine("Processing completed.");
restClient.DownloadResult(task, outputFilePath);
Console.WriteLine("Download completed.");
}
else
{
Console.WriteLine("Error while processing the task");
}
}