保存时设置超时
Contents
[
Hide
]保存时设置超时
Aspose.CAD for .NET API 允许您在保存时设置超时。这在保存过程耗时较长或消耗内存较多的情况下可能会很有帮助。为此,API 提供了 InterruptionTokenSource 类。 InterruptionTokenSource 类提供一个用于中断长时间操作的令牌。
示例代码
以下代码片段演示了 InterruptionTokenSource 类的使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |