/// <summary>
 /// Initializes a new instance of the <see cref="SaveImageWorker" /> class.
 /// </summary>
 /// <param name="inputPath">The path to the input image.</param>
 /// <param name="outputPath">The path to the output image.</param>
 /// <param name="saveOptions">The save options.</param>
 /// <param name="monitor">The interrupt monitor.</param>
 public SaveImageWorker(string inputPath, string outputPath, ImageOptionsBase saveOptions, Multithreading.InterruptMonitor monitor)
 {
     this.inputPath   = inputPath;
     this.outputPath  = outputPath;
     this.saveOptions = saveOptions;
     this.monitor     = monitor;
 }
        public static void InterruptMonitor(string dir, string ouputDir)
        {
            ImageOptionsBase saveOptions = new ImageOptions.PngOptions();

            Multithreading.InterruptMonitor monitor = new Multithreading.InterruptMonitor();
            SaveImageWorker worker = new SaveImageWorker(dir + "big.psb", dir + "big_out.png", saveOptions, monitor);

            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(worker.ThreadProc));

            try
            {
                thread.Start();

                // The timeout should be less than the time required for full image conversion (without interruption).
                System.Threading.Thread.Sleep(3000);

                // Interrupt the process
                monitor.Interrupt();
                System.Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now);

                // Wait for interruption...
                thread.Join();
            }
            finally
            {
                // If the file to be deleted does not exist, no exception is thrown.
                System.IO.File.Delete(dir + "big_out.png");
            }
        }