![](/img/trans.png)
[英]xslTransform.Transform to XslCompiledTransform.Transform
[英]How to cancel an XslTransform.Transform in progress
因此,一旦启动了长期运行的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
调用不是异步的。
您需要在另一个线程中进行转换。 然后,您的主线程在需要取消时必须杀死转换工作者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.