By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

C# Semaphore issue

P: 2
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?

Aug 12 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 7,872
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
Aug 12 '09 #2

P: 2
thanks for your reply
see the code example
Expand|Select|Wrap|Line Numbers
  1.           try
  2.             {
  3.                 semCollectionLock.WaitOne();
  4.                 bDidLock = true;
  7.                 string sKey;
  9.                 stSoapObject = scSystemObject.GetObject()
  11.                 // unlock collection
  12.                 semCollectionLock.Release();
  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.                 }
  31.             }
  32.             return stSoapObject;


The object that is returned (stSoapObjet) is then running a very long process, and when the second thread arrives it hangs on WaitOne
Aug 12 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.