Is there any harm in creating and interrupting a thread in ASP.NET through Response.End ()?

I need to make a COM call and just wait until the call returns. If the call does not return in x seconds, I want to end the request.

Create Threadto make a call.

string output = null;
Thread t = new Thread(() => { output = SomeHelper.DoWork(); });
t.Start();
t.Join(timeout);

if (string.IsNullOrEmpty(output))                
     this.Send500();

The method that completes the response.

protected void Send500()
{
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Status = "500 ServiceUnavailable";
    Response.StatusCode = 500;
    Response.Flush();
    Response.SuppressContent = true;
    Response.End();
}

When it works Response.End(), I get an error Thread was being aborted. It is expected. I'm fine with a mistake. This is normal for what I'm trying to do.

Is there any other reason for concern when this error returns, which I should know about?

+4
source share
2 answers

, Thread.Abort , . , . . .

, , . , . , . , . , COM Semaphore , .

, Response.Flush , . Flush.

+1

, , ?

ASP.NET(. Response.End ). t, COM, , SomeHelper.DoWork() , AppDomain - . , , DoWork(), , .

t.Abort() ( ), t , .

SomeHelper.DoWork() , /, . , COM proc, DLL- . COM factory " SomeHelper -.

+1

Source: https://habr.com/ru/post/1539056/


All Articles