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


C# RestServiceClient.GetTaskStatus方法代码示例

本文整理汇总了C#中RestServiceClient.GetTaskStatus方法的典型用法代码示例。如果您正苦于以下问题:C# RestServiceClient.GetTaskStatus方法的具体用法?C# RestServiceClient.GetTaskStatus怎么用?C# RestServiceClient.GetTaskStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestServiceClient的用法示例。


在下文中一共展示了RestServiceClient.GetTaskStatus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CallOcrWebService

        private static string CallOcrWebService(FileInfo pngFile, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
        {
            var restClient = new RestServiceClient
            {
                Proxy = { Credentials = CredentialCache.DefaultCredentials },
                ApplicationId = ConfigurationManager.AppSettings["ApplicationId"].ToString(),
                Password = ConfigurationManager.AppSettings["Password"].ToString()
            };

            var textFieldProcessingSettings = new TextFieldProcessingSettings
            {
                CustomOptions = "region=" + topLeftX + "," + topLeftY + "," + bottomRightX + "," + bottomRightY,
                Language = "english"
            };

            if (pngFile.DirectoryName == null)
                throw new Exception("png file directory name is blank");

            var outputXmlFile = Path.Combine(pngFile.DirectoryName, GetFileNameWithoutExtension(pngFile) + ".xml");

            // call the REST service
            var task = restClient.ProcessTextField(pngFile.ToString(), textFieldProcessingSettings);
            System.Threading.Thread.Sleep(4000);
            task = restClient.GetTaskStatus(task.Id);
            //Console.WriteLine("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(4000);
                task = restClient.GetTaskStatus(task.Id);
                //Console.WriteLine("Task status: {0}", task.Status);
            }
            if (task.Status == TaskStatus.Completed)
            {
                //Console.WriteLine("Processing completed.");
                restClient.DownloadResult(task, outputXmlFile);
                //Console.WriteLine("Download completed.");
            }
            else
            {
                //Console.WriteLine("Error while processing the task");
                return outputXmlFile;
            }
            return outputXmlFile;
        }
开发者ID:redwards510,项目名称:OCRina,代码行数:51,代码来源:CloudOcrService.cs


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