示例#1
0
        /// <summary>
        /// Runs the specified G'MIC command.
        /// </summary>
        /// <param name="command">The G'MIC command.</param>
        /// <param name="customResourcePath">The custom resource path.</param>
        /// <param name="hostName">The host application name.</param>
        /// <param name="imageList">The image list.</param>
        /// <param name="hasProgressEvent"><c>true</c> if the caller whats progress reports; otherwise, <c>false</c>.</param>
        /// <param name="taskState">The task state.</param>
        /// <exception cref="InvalidOperationException">This G'MIC instance is already running.</exception>
        /// <exception cref="OperationCanceledException">The operation was canceled.</exception>
        public void StartAsync(string command,
                               string customResourcePath,
                               string hostName,
                               GmicImageList imageList,
                               bool hasProgressEvent,
                               GmicRunnerTaskState <TGmicBitmap> taskState)
        {
            if (IsBusy)
            {
                ExceptionUtil.ThrowInvalidOperationException("This G'MIC instance is already running.");
            }

            progress    = -1;
            shouldAbort = 0;

            GmicWorkerArgs args = new GmicWorkerArgs(command,
                                                     customResourcePath,
                                                     hostName,
                                                     imageList,
                                                     hasProgressEvent,
                                                     taskState);

            Task task = Task.Run(() => GmicWorker(args), taskState?.CancellationToken ?? CancellationToken.None);

            IsBusy = TaskIsRunning(task);
        }
示例#2
0
 public GmicWorkerArgs(string command,
                       string customResourcePath,
                       string hostName,
                       GmicImageList imageList,
                       bool hasProgressEvent,
                       GmicRunnerTaskState <TGmicBitmap> taskState)
 {
     Command            = command;
     CustomResourcePath = customResourcePath;
     HostName           = hostName;
     ImageList          = imageList;
     HasProgressEvent   = hasProgressEvent;
     if (taskState != null)
     {
         CanBeCanceled     = taskState.CancellationToken.CanBeCanceled;
         CancellationToken = taskState.CancellationToken;
         Task = taskState.CompletionSource;
     }
     else
     {
         CanBeCanceled     = true;
         CancellationToken = CancellationToken.None;
         Task = null;
     }
 }