异常消息:线程正在中止。 [英] Exception message : thread was being aborted.

查看:147
本文介绍了异常消息:线程正在中止。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常消息:线程正在中止。 

我在prod服务器上运行应用程序时遇到异常。我从来没有在dev和测试环境中得到那个例外。
可以请任何帮助我。如果代码中有任何错误。

我在vb中的代码。


尝试
Dim filePath As String = Request.QueryString(fn)
Response.ContentType = ContentType
Response.AppendHeader(content- disposition,attachment; filename =+ Path.GetFileName(filePath))
Response.TransmitFile(filePath)
Response.Flush()

System.Threading.Thread。 Sleep(1000)
If File.Exists(filePath)Then
File.Delete(filePath)
End if

Response.End()
Catch ex As Exception
oUtility.WriteLog(异常消息:+ ex.Message,True)
vm.stat = 2
vm.message =内部服务器错误
投掷
结束尝试



我在C#中的代码

string filePath = Request.Que ryString [ FN];
Response.ContentType = ContentType;
Response.AppendHeader(content-disposition,attachment; filename =+ Path.GetFileName(filePath));
Response.TransmitFile(filePath);
Response.Flush();

System.Threading.Thread.Sleep(1000);
if(File.Exists(filePath))
{
File.Delete(filePath);
}
//response.writefile(filepath)
Response.End();





我尝试过:



我试图在开发环境中运行该应用程序。我从未遇到过这个问题。我无法重现错误。

解决方案

这是设计好的:

HttpResponse.End Method(System.Web) [< a href =https://docs.microsoft.com/en-gb/dotnet/api/system.web.httpresponse.end\"target =_ blanktitle =New Window> ^ ]:

为了模仿ASP中End方法的行为,此方法尝试引发ThreadAbortException异常。如果此尝试成功,则调用线程将被中止,这对您站点的性能不利。在这种情况下,执行End方法调用后没有代码。



删除 Response.End()调用,并按照文档中的建议将其替换为 Application.CompleteRequest()



HttpApplication.CompleteRequest Method(System.Web)| Microsoft Docs [ ^ ]


Exception Message : Thread was being aborted.

I am getting above exception when running the application in prod server. I never get that exception in dev and in test environment. 
Could any please help me out. If there is anything wrong in the code. 

My code in vb.


  Try
                    Dim filePath As String = Request.QueryString("fn")
                    Response.ContentType = ContentType
                    Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(filePath))
                    Response.TransmitFile(filePath)
                    Response.Flush()

                    System.Threading.Thread.Sleep(1000)
                    If File.Exists(filePath) Then
                        File.Delete(filePath)
                    End If

                    Response.End()
                Catch ex As Exception
                    oUtility.WriteLog("Exception Message : " + ex.Message, True)
                    vm.stat = 2
                    vm.message = "Internal server error"
                    Throw
                End Try



My code in C#

  string filePath = Request.QueryString["fn"];
                        Response.ContentType = ContentType;
                        Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(filePath));
                        Response.TransmitFile(filePath);
                        Response.Flush();

                        System.Threading.Thread.Sleep(1000);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        //response.writefile(filepath)
                        Response.End();



What I have tried:

I tried to run the application in dev environment. I never got that issue. I could not reproduce the error.

解决方案

This is by design:

To mimic the behavior of the End method in ASP, this method tries to raise a ThreadAbortException exception. If this attempt is successful, the calling thread will be aborted, which is detrimental to your site's performance. In that case, no code after the call to the End method is executed.


Remove the Response.End() call, and replace it with Application.CompleteRequest(), as suggested in the documentation.

HttpApplication.CompleteRequest Method (System.Web) | Microsoft Docs[^]


这篇关于异常消息:线程正在中止。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆