那么一旦您启动了长时间运行的 XslTransform.Transform,您将如何中止它?
XslTransform XslTransform = new XslTransform();
XmlDocument stylesheetDocument = new XmlDocument();
//TODO: Handle error when styhlesheet doe snot exist
stylesheetDocument.LoadXml(stylesheetXml);
XslTransform.Load(stylesheetDocument.CreateNavigator());
FileStream FileStream = new FileStream(outputDocument.Path, FileMode.Create);
try
{
XslTransform.Transform(inputXmlDocument, XsltArgumentList, FileStream); // raises XSLTException
}
catch (XsltException xsltException)
{
MessageBox.Show(xsltException.Message);
}
catch (XPathException xPathException)
{
MessageBox.Show(xPathException.Message);
}
catch (Exception)
{
throw;
}
FileStream.Close();
最佳答案
不幸的是,Transform
调用不是异步的。
您需要在另一个线程中进行转换。当需要取消转换工作线程时,您的主线程将不得不终止转换工作线程。
关于c# - 如何取消正在进行的 XslTransform.Transform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027913/