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

Lock statement in C#, Is there an equivalent in VB.NET?

P: n/a
Hi,
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic
Feb 6 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a

http://msdn.microsoft.com/library/de...kStatement.asp

"The lock keyword marks a statement block as a critical section by
obtaining the mutual-exclusion lock for a given object, executing a
statement, and then releasing the lock. This statement takes the
following form:

lock(expression) statement_block

where:

expression
Specifies the object that you want to lock on. expression must be a
reference type."

ThunderMusic wrote:
Hi,
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic

Feb 6 '06 #2

P: n/a
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> schrieb:
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}


'SyncLock'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #3

P: n/a
AFAIK this is the "SyncLock" statement...

--
Patrice

"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> a écrit dans le message de
news:uO**************@TK2MSFTNGP10.phx.gbl...
Hi,
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic

Feb 6 '06 #4

P: n/a

SyncLock ... End SyncLock
ThunderMusic wrote:
Hi,
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic

Feb 6 '06 #5

P: n/a
thanks a lot for the quick answer!!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news: uw**************@TK2MSFTNGP09.phx.gbl...
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> schrieb:
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}


'SyncLock'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #6

P: n/a
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> schrieb:
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}


'SyncLock'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #7

P: n/a
"Peter Rilling" <pe***@nospam.rilling.net> schrieb:
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)


Not really. 'Lock' is far too generic to be self-descriptive.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #8

P: n/a
Thats a matter of taste. By using longer and almost always more descriptive
keywords and variable names, VB programs tend to require less line by line
documentation. Both languages still need docs on a program's theory of
operations, but VB requires less line by line stuff.

I also program in C++, so I do have the background to compare the BASIC and
C languages and their descendents.

Mike Ober.

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OO*************@TK2MSFTNGP11.phx.gbl...
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> schrieb:
The subject says it all. Is there an equivalent, in VB.NET, for the C# statement Lock(Object){}


'SyncLock'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>



Feb 7 '06 #9

P: n/a
CMM
Not to mention that "Lock" was a keyword in VB.Classic (and B.A.S.I.C. going
back to the old days) as part of the "Open file For..." as well as a
standalone statement in VB.Classic (Lock #filenum) and a now function in
VB.NET.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:us*************@TK2MSFTNGP10.phx.gbl...
"Peter Rilling" <pe***@nospam.rilling.net> schrieb:
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)


Not really. 'Lock' is far too generic to be self-descriptive.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 7 '06 #10

P: n/a
Peter,
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)

Do you now understand why there is in VBNet less need for XML or other
documentation.

I hate to read those C# programs with for every line of code 5 lines of
documentation.

Cor

Feb 7 '06 #11

P: n/a
Michael D. Ober <obermd.@.alum.mit.edu.nospam> wrote:
Thats a matter of taste. By using longer and almost always more descriptive
keywords and variable names, VB programs tend to require less line by line
documentation. Both languages still need docs on a program's theory of
operations, but VB requires less line by line stuff.


If one requires line-by-line documentation in C# for the basics of the
language, the code can't be very good.

I only write documentation inside methods to give a general overview of
what's happening in a section (which often leads to refactoring of that
section into its own method) or if a statement is clear in terms of
what it's doing at a low level, but not in terms of its overall effect.

Neither of these would be reduced by using a more verbose language.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #12

P: n/a
Cor Ligthert [MVP] <no************@planet.nl> wrote:
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)
Do you now understand why there is in VBNet less need for XML or other
documentation.
Absolutely not. When you're calling a method, you still need to know
what it's going to do, preferrably without having to look at the method
implementation.
I hate to read those C# programs with for every line of code 5 lines of
documentation.


So would I - because that's clearly badly written code. See my response
to Mike for more details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #13

P: n/a
"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb:
> Once again the VB.NET designers felt it necessary to use more letter
> than
> necessary in their keywords. :-)
Do you now understand why there is in VBNet less need for XML or other
documentation.


Absolutely not. When you're calling a method, you still need to know
what it's going to do, preferrably without having to look at the method
implementation.


I agree with you. XML documentation is especially important when selling
class libraries and writing reusable code.
I hate to read those C# programs with for every line of code 5 lines of
documentation.


So would I - because that's clearly badly written code. See my response
to Mike for more details.


ACK. However, I still think that 'SyncLock' is more self-descriptive and
thus a better choice than 'lock'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 7 '06 #14

P: n/a
Herfried K. Wagner [MVP] <hi***************@gmx.at> wrote:
So would I - because that's clearly badly written code. See my response
to Mike for more details.


ACK. However, I still think that 'SyncLock' is more self-descriptive and
thus a better choice than 'lock'.


To be honest, I don't think there's a lot of ambiguity in either case.
One thing I have against "lock" is that it would often be my choice of
name for a variable used for locking purposes.

Then again, I'd prefer it if there were no keyword at all, and "using"
statements were used instead, giving a much more flexible framework.
See http://www.pobox.com/~skeet/csharp/m...e/locking.html for
more...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.