asp.netmultithreadingiishttpapplication

Can a thread in ASP.NET work keep continue after Response.End?


I want to make a tcp connection to a device and keep continously retrieve data from device. I want to start this with a simple request and keep it working background even Page response completed. Is this possible in asp.net?


Solution

  • Can a thread in ASP.NET work keep continue after Response.End?

    Yes, you can if you do not care or do not need the result.

    For example, in the following code, you call AddLogAsync and insert a log, but you not care whether insert successful or not.

    public Task AddLogAsync(Log log)
    {
       return Task.Run(() => AddLog(log));
    }
    
    private void AddLog(TraceLog traceLog)
    {
       // Do something here.
    }
    

    I want to make a tcp connection to a device and keep continously retrieve data from device. I want to start this with a simple request and keep it working. Is this possible in asp.net?

    I'm not really understanding above question. After Response.End, you cannot return anything, although you can continue work on something in different thread.