Currently I am launching a long running thread in Startup.Auth.cs
which is where ConfigureAuth
is called by the ASP.NET app when the application is starting. Currently I am launching my thread here with the following:
try {
LaunchListenThread();
}
catch (ThreadAbortException e) {
Console.WriteLine("Thread - caught ThreadAbortException - resetting.");
Console.WriteLine("Exception message: {0}", e.Message);
Thread.ResetAbort();
LaunchListenThread();
}
The function LaunchListenThread()
essentially just launches the thread that is declared in Startup.Auth.cs
The thread is declared as
private readonly ThreadStart nThread = new ThreadStart(NetComms.StartListening);
My primary concern here is catching a ThreadAbortException
, which for example, if I throw in StartListening
, it does not appear to be caught by the previously mentioned Catch
block.
What I am wondering is a more standard or accepted way of launching a long-running thread like this in IIS, particularly in which I am able to catch a ThreadAbortException
I have tested so far by doing the following:
System.Threading.Thread.CurrentThread.Abort();
catch(ThreadAbortException te) {
throw te;
}
The error is thrown, but it is lost thereafter.
Please let me know if any additional information would be helpful.