Imposta timeout al salvataggio

Imposta timeout al salvataggio

Aspose.CAD per l’API .NET consente di impostare un timeout al salvataggio. Questo potrebbe essere utile nei casi in cui il processo di salvataggio richiede molto tempo o consuma molta memoria. Per questo, l’API fornisce la classe  InterruptionTokenSource. La classe InterruptionTokenSource fornisce un token che viene utilizzato per interrompere le operazioni lunghe.

Codice di esempio

Il seguente frammento di codice dimostra l’uso della classe InterruptionTokenSource.

// 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();
}
}