Class InterruptMonitor

Class InterruptMonitor

Namespace: Aspose.Imaging.Multithreading
Assembly: Aspose.Imaging.dll (25.7.0)

Represents information about interruption.

public class InterruptMonitor : IInterruptMonitor
   {
   }
Given that you provided an empty class, this is the minimum required output to meet the formatting requirement. In practice, a full class with methods or properties would be reformatted as follows:
public class InterruptMonitor : IInterruptMonitor
{
    private readonly SomeType _someField; // assume there's some type and field here...
    public InterruptMonitor(SomeType someField)
    {
        _someField = someField;
    }
    public void SomeMethod()
    {
    }
}

Inheritance

object InterruptMonitor

Implements

IInterruptMonitor

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

The following example shows how to perform the image conversion in a dedicated thread and interrupt the process in a few seconds after starting.

private class Worker
   {
       private readonly string inputPath;
       private readonly string outputPath;
       private readonly Aspose.Imaging.ImageOptionsBase saveOptions;
       private readonly Aspose.Imaging.Multithreading.InterruptMonitor monitor;
       public Worker(string inputPath, string outputPath, Aspose.Imaging.ImageOptionsBase saveOptions, Aspose.Imaging.Multithreading.InterruptMonitor monitor)
       {
           this.inputPath = inputPath;
           this.outputPath = outputPath;
           this.saveOptions = saveOptions;
           this.monitor = monitor;
       }
       public void ThreadProc()
       {
           try
           {
               Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(this.inputPath);
               Aspose.Imaging.Multithreading.InterruptMonitor.ThreadLocalInstance = this.monitor;
               try
               {
                   image.Save(this.outputPath, this.saveOptions);
               }
               catch (Aspose.Imaging.CoreExceptions.OperationInterruptedException e)
               {
                   System.Console.WriteLine(
                       "The worker thread #{0} has been interrupted at {1}",
                       System.Threading.Thread.CurrentThread.ManagedThreadId,
                       System.DateTime.Now);
               }
               finally
               {
                   image.Dispose();
                   Aspose.Imaging.Multithreading.InterruptMonitor.ThreadLocalInstance = null;
               }
           }
           catch (System.Exception e)
           {
               System.Console.WriteLine(e);
           }
       }
   }
   string baseDir = "c:\\temp\\";
   Aspose.Imaging.Multithreading.InterruptMonitor monitor = new Aspose.Imaging.Multithreading.InterruptMonitor();
   Worker worker = new Worker(baseDir + "big.png", baseDir + "big.bmp", new Aspose.Imaging.ImageOptions.BmpOptions(), monitor);
   System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(worker.ThreadProc));
   thread.Start();
   System.Threading.Thread.Sleep(2000);
   monitor.Interrupt();
   System.Console.WriteLine("Interrupting the worker thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now);
   thread.Join();
   System.Console.WriteLine("Done. Press ENTER to exit.");
   System.Console.ReadLine();

Constructors

InterruptMonitor()

public InterruptMonitor()
   {
   }

Properties

IsInterrupted

Gets the value indicating whether operations should be interrupted.

public virtual bool IsInterrupted
   {
      get;
   }

Property Value

bool

ThreadLocalInstance

Gets or sets the IInterruptMonitor instance which is unique for each thread.

public static IInterruptMonitor ThreadLocalInstance
    {
        get;
        set;
    }

Property Value

IInterruptMonitor

Methods

Interrupt()

Sends a request to interrupt operations.

public virtual void Interrupt()
    {
    }

Examples

The following example shows how to perform the image conversion in a dedicated thread and interrupt the process in a few seconds after starting.

private class Worker
   {
       private readonly string inputPath;
       private readonly string outputPath;
       private readonly Aspose.Imaging.ImageOptionsBase saveOptions;
       private readonly Aspose.Imaging.Multithreading.InterruptMonitor monitor;
       public Worker(string inputPath, string outputPath, Aspose.Imaging.ImageOptionsBase saveOptions, Aspose.Imaging.Multithreading.InterruptMonitor monitor)
       {
           this.inputPath = inputPath;
           this.outputPath = outputPath;
           this.saveOptions = saveOptions;
           this.monitor = monitor;
       }
       public void ThreadProc()
       {
           try
           {
               Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(this.inputPath);
               Aspose.Imaging.Multithreading.InterruptMonitor.ThreadLocalInstance = this.monitor;
               try
               {
                   image.Save(this.outputPath, this.saveOptions);
               }
               catch (Aspose.Imaging.CoreExceptions.OperationInterruptedException e)
               {
                   System.Console.WriteLine(
                       "The worker thread #{0} has been interrupted at {1}",
                       System.Threading.Thread.CurrentThread.ManagedThreadId,
                       System.DateTime.Now);
               }
               finally
               {
                   image.Dispose();
                   Aspose.Imaging.Multithreading.InterruptMonitor.ThreadLocalInstance = null;
               }
           }
           catch (System.Exception e)
           {
               System.Console.WriteLine(e);
           }
       }
   }
   string baseDir = "c:\\temp\\";
   Aspose.Imaging.Multithreading.InterruptMonitor monitor = new Aspose.Imaging.Multithreading.InterruptMonitor();
   Worker worker = new Worker(baseDir + "big.png", baseDir + "big.bmp", new Aspose.Imaging.ImageOptions.BmpOptions(), monitor);
   System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(worker.ThreadProc));
   thread.Start();
   System.Threading.Thread.Sleep(2000);
   monitor.Interrupt();
   System.Console.WriteLine("Interrupting the worker thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now);
   thread.Join();
   System.Console.WriteLine("Done. Press ENTER to exit.");
   System.Console.ReadLine();
 English