2
private static readonly object _accessLock = new object();

private void doStuff()
{
    lock (_accessLock)
    {
        //code
    }
}

I am trying to debug a problem where 'doStuff' method is blocking several threads. This function is running as part of web application which is hosted on IIS.

In the context of IIS, is it possible that thread dies after acquiring the lock and rest of the threads can not acquire the lock?

Icarus3
  • 2,310
  • 14
  • 22
  • No is not possible, however (and not having much information from your question) there is a specific technicality when dealing with IIS and ASP.Net you must take in account, the "Thread Agility", there is no guarantee in ASP.Net that the thread that "starts the work" is the same thread that "Completes the work", so if you have some async call that make use of a completion port for instance you can run into issues. You can read more on this SO question: https://stackoverflow.com/questions/33345879/asp-net-thread-agility-how-to-overcome or just google about it. – Jesus Salas Mar 15 '19 at 23:44
  • Please check if this helps: https://stackoverflow.com/questions/4239804/what-happens-with-lock-when-thread-gets-closed-while-the-lock-is-set. Basicaly, when lIS terminates a thread, a ThreadAbortException is thrown so our code can clean up before the thread actually shuts down. – Khanh TO Mar 16 '19 at 03:13
  • Looks like XY problem question. – Dmytro Mukalov Mar 16 '19 at 08:12

0 Answers0