|
-
Dec 24th, 2009, 06:50 PM
#1
Re: how to check if Mutex is Released
 Originally Posted by pacerier
i think the code u provided above would not work:
Code:
Get
If InSet Then
SyncLock Lock
Return _SomeString
End SyncLock
Else
Return _SomeString
End If
End Get
because after you have Returned, everything else below it does not run. So the Lock never gets released. so what we have is this:
Code:
Get
If InSet Then
SyncLock Lock
End SyncLock
Return _SomeString
Else
Return _SomeString
End If
End Get
No that is not the case, when you come out of the scope of a SyncLock block the lock will be released - it doesnt have to actually hit the End SyncLock line. Just like if you use a Using statement, you dont have to hit the End Using line for the object to be disposed, its just when you come out of the scope of that statement. I assume this behaviour is achieved by the fact that internally the SyncLock uses a Try/Catch/Finally block and releases the lock in the Finally block. You can see the same behaviour yourself if you just do something like this inside a Function:
vb.net Code:
Try
Dim something As String = "Some text"
Return something
Catch
MessageBox.Show("Oh dear")
Finally
MessageBox.Show("Merry Christmas") 'seasonal examples FTW
End Try
Now if you run that function you will see that you get your 'something' object returned but the Finally block is still reached so you should still see the Merry Christmas message box
Last edited by chris128; Dec 24th, 2009 at 06:54 PM.
-
Dec 26th, 2009, 01:47 AM
#2
Thread Starter
Hyperactive Member
Re: how to check if Mutex is Released
 Originally Posted by chris128
No that is not the case, when you come out of the scope of a SyncLock block the lock will be released - it doesnt have to actually hit the End SyncLock line. Just like if you use a Using statement, you dont have to hit the End Using line for the object to be disposed, its just when you come out of the scope of that statement. I assume this behaviour is achieved by the fact that internally the SyncLock uses a Try/Catch/Finally block and releases the lock in the Finally block. You can see the same behaviour yourself if you just do something like this inside a Function:
what if i had something like this:
Code:
1: SyncLock Lock
GoTo 1
End SyncLock
does the thread leaves synclock when it hits GoTo 1 or does he enters the lock 2 times, den 3, den 4 ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|