Set timeout on save

Set timeout on save

Aspose.CAD for .NET API allows you to set a timeout on save. This might be helpful in cases where the saving process is taking a lot of time or consuming a lot of memory. For this, the API provides the  InterruptionTokenSource class. The InterruptionTokenSource class provides a token that is used to interrupt long operations.

Sample Code

The following code snippet demonstrates the use of the InterruptionTokenSource class.

// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET
string SourceDir = RunExamples.GetDataDir_DWGDrawings();
string OutputDir = RunExamples.GetDataDir_Output();
using (Image cadDrawing = Image.Load(SourceDir + "Drawing11.dwg"))
{
var rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.PageWidth = cadDrawing.Size.Width;
rasterizationOptions.PageHeight = cadDrawing.Size.Height;
using (var its = new InterruptionTokenSource())
{
PdfOptions CADf = new PdfOptions();
CADf.VectorRasterizationOptions = rasterizationOptions;
CADf.InterruptionToken = its.Token;
var exportTask = Task.Factory.StartNew(() =>
{
cadDrawing.Save(OutputDir + "PutTimeoutOnSave_out.pdf", CADf);
});
Thread.Sleep(10000);
its.Interrupt();
exportTask.Wait();
}
}