Connecting Tech Pros Worldwide Forums | Help | Site Map

C# Semaphore issue

Newbie
 
Join Date: Aug 2009
Posts: 2
#1: Aug 12 '09
Hi All,

I'll be happy to get your opinionn this, i have a webservice that uses Semaphore to access shared (VB) resources and i noticed that the semaphore could not make locks using the WaitOne() method, when using it, it throws an exception "Thread was being aborted." after 2 minutes.
I believe its aprobably a timeout error, but not sure what is the cause..

Can someone please explain what effects the lock? why t could be completed? what effects the timeout and can i configure somthing on the code or IIS or machine level to prevent that?

Thanks

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Aug 12 '09

re: C# Semaphore issue


The 2minutes is probably IISs page timeout. When it hits that it aborts the thread that is running the page code.
If your page is really waiting longer then that, you might want to consider changing how things work. I cannot imagine waiting that long for a webpage
Newbie
 
Join Date: Aug 2009
Posts: 2
#3: Aug 12 '09

re: C# Semaphore issue


thanks for your reply
see the code example
Expand|Select|Wrap|Line Numbers
  1.           try
  2.             {
  3.                 semCollectionLock.WaitOne();
  4.                 bDidLock = true;
  5.  
  6.  
  7.                 string sKey;
  8.  
  9.                 stSoapObject = scSystemObject.GetObject()
  10.  
  11.                 // unlock collection
  12.                 semCollectionLock.Release();
  13.  
  14.  
  15.  
  16.             }
  17.             catch (Exception e)
  18.             {
  19.                 if (bDidLock)
  20.                 {
  21.                     try
  22.                     {
  23.                         semCollectionLock.Release();
  24.                     }
  25.                     catch
  26.                     {
  27.                         StaticMethods.WriteErrorToLog(MethodName, "Get - Error Releasing Semaphore..." + sSessionKey, iRandom);
  28.                     }
  29.                 }
  30.  
  31.             }
  32.             return stSoapObject;
  33.  

--------------------

The object that is returned (stSoapObjet) is then running a very long process, and when the second thread arrives it hangs on WaitOne
Reply