示例#1
0
        public bool IsTaskFinished(TaskId taskId)
        {
            TaskStatus status = TaskStatus.Unknown;

            lock (allTasks)
            {
                status = allTasks[taskId].Status;
            }

            if (status == TaskStatus.Unknown || OcrSdkTask.IsTaskActive(status))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        /// <summary>
        /// Submit and process image asynchronously.
        /// Performs callbacks:
        ///   UploadFileCompleted
        ///   TaskProcessingCompleted
        /// </summary>
        /// <param name="filePath">Path to file in isolated storage</param>
        /// <param name="settings"></param>
        /// <param name="userState"></param>
        public void ProcessImageAsync(string filePath, ProcessingSettings settings, object userState)
        {
            BackgroundWorker w = new BackgroundWorker();

            w.DoWork += new DoWorkEventHandler((sender, e) =>
            {
                OcrSdkTask task = null;
                try
                {
                    task = _syncClient.ProcessImage(filePath, settings);
                    UploadCompletedEventArgs uploadArgs = new UploadCompletedEventArgs(task, userState);
                    onUploadFileCompleted(sender, uploadArgs);

                    // Wait until task finishes
                    while (true)
                    {
                        task = _syncClient.GetTaskStatus(task.Id);
                        if (!task.IsTaskActive())
                        {
                            break;
                        }
                        Thread.Sleep(1000);
                    }

                    if (task.Status == TaskStatus.NotEnoughCredits)
                    {
                        throw new Exception("Not enough credits to process image. Please add more pages to your application's account.");
                    }

                    TaskEventArgs taskArgs = new TaskEventArgs(task, null, false, userState);

                    onProcessingCompleted(sender, taskArgs);
                }
                catch (Exception ex)
                {
                    TaskEventArgs taskArgs = new TaskEventArgs(task, ex, false, userState);
                    onProcessingCompleted(sender, taskArgs);
                }
            }
                                               );

            w.RunWorkerAsync();
        }