Asp.net mvc 4 将调度程序与线程一起使用

Asp.net mvc 4 将调度程序与线程一起使用,asp.net-mvc-4,thread-safety,richtextbox,dispatcher,Asp.net Mvc 4,Thread Safety,Richtextbox,Dispatcher,我有一个需要转换为html的rtf字符串列表。我正在使用richtextbox控件将rtf转换为html。我的问题是 该解决方案也应该有效,但如何在代码中实现该解决方案 public string ConvertRtfToHtml(string rtfText) { try { var thread = new Thread(ConvertRtfInSTAThread); v

我有一个需要转换为html的rtf字符串列表。我正在使用richtextbox控件将rtf转换为html。我的问题是

该解决方案也应该有效,但如何在代码中实现该解决方案

public string ConvertRtfToHtml(string rtfText)
    {

        try
        {
            var thread = new Thread(ConvertRtfInSTAThread);                
            var threadData = new ConvertRtfThreadData { RtfText = rtfText };
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(threadData);

            try
            {
                thread.Join();
            }
            catch(ThreadStateException e){
                logger.Error("ThreadStateException " + e.Message);
            }
            catch (ThreadInterruptedException e) {
                logger.Error("ThreadInterruptedException " + e.Message);
            }                


            return threadData.HtmlText;

        }
        catch (Exception e){
            logger.Error("ConvertRtfToHtml: " + e.InnerException.Message);
            return "Error";
        }

    }

private void ConvertRtfInSTAThread(object rtf)
    {
        MarkupConverter.MarkupConverter markupConverter = new MarkupConverter.MarkupConverter(); 

        var threadData = rtf as ConvertRtfThreadData;

        try
        {
            threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText);
        }
        catch(Exception e){
            logger.Error("ConvertRtfInSTAThread: " + e.Message);
        }

    }
此markupconverter.convertrtftohtml使用richtextbox控件

在上面的代码中,我在哪里安装调度器

 Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
Dispatcher.Run();
我使用它如下

private void ConvertRtfInSTAThread(object rtf)
    {
        MarkupConverter.MarkupConverter markupConverter = new MarkupConverter.MarkupConverter(); 

        var threadData = rtf as ConvertRtfThreadData;

        try
        {
            threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText);

            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
            Dispatcher.Run();
        }
        catch(Exception e){
            logger.Error("ConvertRtfInSTAThread: " + e.Message);
        }

    }

由于MS关闭了Connect,链路已断开