繁体   English   中英

如何取消正在进行的XslTransform.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM