Example #1
0
        /// <summary>
        /// Начать обработку файла.
        /// </summary>
        public void Process()
        {
            lock (processLocker)
            {
                if (_processThread != null)
                {
                    if (_processThread.ThreadState == ThreadState.Stopped)
                    {
                        throw new FileIsAlreadyProcessedException();
                    }
                    else
                    {
                        throw new ProcessIsAlreadyRunningException();
                    }
                }

                _processThread = new Thread(() =>
                {
                    try
                    {
                        using (var pngProcessor = new PngProcessor())
                        {
                            pngProcessor.ProgressChanged += (double progress) => { Progress = progress; };
                            pngProcessor.Process(_filePath);
                        }
                    }
                    finally
                    {
                        ProcessedEvent?.Invoke(this);
                    }
                });
                _processThread.Start();
            }
        }
        public void RunProcessing(string fileId, string filePath, IJobCancellationToken cancellationToken)
        {
            using (var processor = new PngProcessor())
            {
                processor.ProgressChanged += (status) =>
                {
                    ImageProcessingStorage.UpdateFileStatus(fileId, status);
                };
                ImageProcessingStorage.UpdateFileStatus(fileId, 0);
                processor.Process(filePath);

                // Sadly, but I can't schedule it as a continuation of current job.
                BackgroundJob.Schedule(() => ImageProcessingStorage.RemoveFileJobPairByFileName(fileId), DateTime.Now.AddMinutes(10));
            }
        }