c# - 如何取消正在进行的 XslTransform.Transform

标签 c# .net xslt

那么一旦您启动了长时间运行的 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/

相关文章:

带有其他参数的 C# HttpClient Post 字符串数组

c# 如何将 float 转换为 int

c# - 如何在 mvvmcross View 模型中使用异步?

c# - FillRectangle 未使用提供的 SolidBrush 的精确颜色进行填充

XSLT/Xpath : Why is it not possible to use the shortened notation for parent for the use attribute of the key function

javascript - 显示大型列表的最佳实践

java - 将 xml 文档作为参数传递给 xsl

c# - C# XNA 游戏中的文本框

.net - 如何跨程序集将元数据与类定义分开?

.net - 从哪里可以得到用 C# 编写的精心设计和编码的应用程序来学习?