How to do this C# code in VB??

G

G Dean Blake

This is some C# code out of a book that is part of a server component using
Application state. I'm trying to convert it to VB. I can't find the VB
equivilent of the Lock. I thought it might be a Mutex but those docs look
different. What is the VB equivelent of the Lock code below?
Thanks,
G

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
switch (TrackingMode){
case PageTrackingMode.ByApplication:
// Update the page hits in the Application
// object. This operation needs a lock because
// multiple users could access a page at the same
// time.
lock(Page.GetType()){
Page.Application[HitsKey] = Hits + 1;
}
break;
 
I

Imran Koradia

The VB.NET equivalent is SyncLock:

SyncLock Page.GetType()
Page.Application(HitsKey) = Hits + 1
End SyncLock

hope that helps..
Imran.
 
L

Lucas Tam

This is some C# code out of a book that is part of a server component
using Application state. I'm trying to convert it to VB. I can't
find the VB equivilent of the Lock. I thought it might be a Mutex but
those docs look different. What is the VB equivelent of the Lock code
below? Thanks,
G

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
switch (TrackingMode){
case PageTrackingMode.ByApplication:
// Update the page hits in the Application
// object. This operation needs a lock because
// multiple users could access a page at the same
// time.
lock(Page.GetType()){
Page.Application[HitsKey] = Hits + 1;
}
break;

Could that be a HttpApplicationState.Lock (Application.Lock)?

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfSystemWebHttpApplicationStateClassLockTopic.asp
 
H

Herfried K. Wagner [MVP]

Imran Koradia said:
The VB.NET equivalent is SyncLock:

SyncLock Page.GetType()
Page.Application(HitsKey) = Hits + 1
End SyncLock

If possible, avoid locking on a type object...
 
G

G Dean Blake

I'm in a class inherrited from WebControl and there is no Application object
as there is when in an aspx page.
G
Lucas Tam said:
This is some C# code out of a book that is part of a server component
using Application state. I'm trying to convert it to VB. I can't
find the VB equivilent of the Lock. I thought it might be a Mutex but
those docs look different. What is the VB equivelent of the Lock code
below? Thanks,
G

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
switch (TrackingMode){
case PageTrackingMode.ByApplication:
// Update the page hits in the Application
// object. This operation needs a lock because
// multiple users could access a page at the same
// time.
lock(Page.GetType()){
Page.Application[HitsKey] = Hits + 1;
}
break;

Could that be a HttpApplicationState.Lock (Application.Lock)?

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfSystemWebHttpApplicationStateClassLockTopic.asp
 
G

G Dean Blake

ah, that's it.
thanks,
G

Imran Koradia said:
The VB.NET equivalent is SyncLock:

SyncLock Page.GetType()
Page.Application(HitsKey) = Hits + 1
End SyncLock

hope that helps..
Imran.

G Dean Blake said:
This is some C# code out of a book that is part of a server component using
Application state. I'm trying to convert it to VB. I can't find the VB
equivilent of the Lock. I thought it might be a Mutex but those docs
look
different. What is the VB equivelent of the Lock code below?
Thanks,
G

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
switch (TrackingMode){
case PageTrackingMode.ByApplication:
// Update the page hits in the Application
// object. This operation needs a lock because
// multiple users could access a page at the same
// time.
lock(Page.GetType()){
Page.Application[HitsKey] = Hits + 1;
}
break;
 

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

Top