当前位置: 首页>>代码示例>>C#>>正文


C# Task.IsTaskActive方法代码示例

本文整理汇总了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;
 }
开发者ID:jaithumar,项目名称:ocrsdk.com,代码行数:18,代码来源:Test.cs

示例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");
            }
        }
开发者ID:RamdhanChoudhary,项目名称:ocrsdk.com,代码行数:26,代码来源:Test.cs


注:本文中的Task.IsTaskActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。