可中断库的支持
Contents
[
Hide
]
可中断库
现在在 Aspose.Slides 中添加了 InterruptionToken 结构和 InterruptionTokenSource 类。这些类型支持中断长时间运行的任务,例如反序列化、序列化或渲染。InterruptionTokenSource 表示传递给 ILoadOptions.InterruptionToken 的令牌或多个令牌的来源。当 ILoadOptions.InterruptionToken 被设置并且此 LoadOptions 实例传递给 Presentation 构造函数时,与此 Presentation 相关的任何长时间运行的任务将在调用 InterruptionTokenSource.Interrupt 方法时被中断。
下面的代码片段演示了如何中断运行中的任务。
This file contains hidden or 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(); | |