Đặt thời gian chờ khi lưu
Đặt thời gian chờ khi lưu
Aspose.CAD cho .NET API cho phép bạn đặt thời gian chờ khi lưu. Điều này có thể hữu ích trong các trường hợp quá trình lưu đang mất nhiều thời gian hoặc tiêu tốn nhiều bộ nhớ. Để làm điều này, API cung cấp lớp InterruptionTokenSource. Lớp InterruptionTokenSource cung cấp một token được sử dụng để ngắt các thao tác dài.
Mẫu mã
Đoạn mã sau đây minh họa việc sử dụng lớp 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(); | |
} | |
} |