可中断库支持
Contents
[
Hide
]
可中断库
现在在 Aspose.Slides 中添加了 InterruptionToken 结构和 InterruptionTokenSource 类。这些类型支持对长时间运行任务的中断,例如反序列化、序列化或渲染。InterruptionTokenSource 代表传递给 ILoadOptions.InterruptionToken 的令牌或多个令牌的源。当设置 ILoadOptions.InterruptionToken 并将此 LoadOptions 实例传递给 Presentation 构造函数时,与此 Presentation 相关的任何长时间运行任务将在调用 InterruptionTokenSource.Interrupt 方法时被中断。
以下代码片段演示了正在运行的任务的中断。
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/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java | |
final InterruptionTokenSource tokenSource = new InterruptionTokenSource(); | |
Runnable interruption = new Runnable() { | |
public void run() { | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.setInterruptionToken(tokenSource.getToken()); | |
Presentation pres = new Presentation("pres.pptx", loadOptions); | |
try{ | |
pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720)); | |
pres.save("pres.ppt", SaveFormat.Ppt); | |
} | |
finally { | |
pres.dispose(); | |
} | |
} | |
}; | |
Thread thread = new Thread(interruption);// run action in a separate thread | |
thread.start(); | |
Thread.sleep(5000); // some work | |
tokenSource.interrupt(); | |