How to check if Mutex is set

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

Dear colleagues

I do the following:
Private Shared mutRefresh as New Mutex()

Before I call mutRefresh.ReleaseMutex() how can I check if
mutRefresh.WaitOne was called?

I realised that the I receive an exception if I call
mutRefresh.ReleaseMutex() before mutRefresh.WaitOne().

Hope somebody can help me.
Thanks Alex
 
Alex,
Before I call mutRefresh.ReleaseMutex() how can I check if
mutRefresh.WaitOne was called?
The routine that you are calling ReleaseMutex from should be the routine
that you called WaitOne from! So there should be no need to "check" if you
called WaitOne first.

Something like:

Private theMutex As New System.Threading.Mutex

Private Sub DoWork()
theMutex.WaitOne()
Try
' do work here
Finally
theMutex.ReleaseMutex()
End Try
End Sub

Calling WaitOne first, makes you the owner of the Mutext, ensuring that
noone else can own the "resource", calling ReleaseMutex releases you as the
owner of the Mutext.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top