Home All Groups Group Topic Archive Search About

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

Author
6 Feb 2006 5:46 PM
ThunderMusic
Hi,
    The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic

Author
6 Feb 2006 5:50 PM
Herfried K. Wagner [MVP]
"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/>
Author
6 Feb 2006 5:53 PM
ThunderMusic
thanks a lot for the quick answer!!

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> a écrit dans le
message de news: uwoo0W0KGHA.3***@TK2MSFTNGP09.phx.gbl...
Show quoteHide quote
> "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/>
Author
6 Feb 2006 6:03 PM
Peter Rilling
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords.  :-)

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uwoo0W0KGHA.3492@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/>
Author
6 Feb 2006 6:11 PM
Herfried K. Wagner [MVP]
"Peter Rilling" <peter@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/>
Author
7 Feb 2006 6:25 AM
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.


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:us0rzi0KGHA.952@TK2MSFTNGP10.phx.gbl...
> "Peter Rilling" <peter@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/>
Author
7 Feb 2006 2:55 AM
Michael D. Ober
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.

Show quoteHide quote
"Peter Rilling" <peter@nospam.rilling.net> wrote in message
news:OOCbwe0KGHA.668@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]" <hirf-spam-me-here@gmx.at> wrote in message
> news:uwoo0W0KGHA.3492@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/>
>
>
>
Author
7 Feb 2006 7:30 AM
Jon Skeet [C# MVP]
Michael D. Ober <ober***@.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
Author
7 Feb 2006 7:00 AM
Cor Ligthert [MVP]
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
Author
7 Feb 2006 7:32 AM
Jon Skeet [C# MVP]
Cor Ligthert [MVP] <notmyfirstn***@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
Author
7 Feb 2006 11:43 AM
Herfried K. Wagner [MVP]
"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/>
Author
7 Feb 2006 5:34 PM
Jon Skeet [C# MVP]
Herfried K. Wagner [MVP] <hirf-spam-me-here@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/miscutil/usage/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
Author
6 Feb 2006 5:50 PM
Patrice
AFAIK this is the "SyncLock" statement...

--
Patrice

Show quoteHide quote
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> a écrit dans le message de
news:uOyxyU0KGHA.3732@TK2MSFTNGP10.phx.gbl...
> Hi,
>     The subject says it all. Is there an equivalent, in VB.NET, for the C#
> statement Lock(Object){}
>
> Thanks
>
> ThunderMusic
>
>
Author
6 Feb 2006 5:50 PM
John Bailo
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfLockStatement.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:
Show quoteHide quote
> Hi,
>     The subject says it all. Is there an equivalent, in VB.NET, for the C#
> statement Lock(Object){}
>
> Thanks
>
> ThunderMusic
>
>
Author
6 Feb 2006 5:52 PM
John Bailo
SyncLock ... End SyncLock


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