Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

locking static/shared objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 14 Sep 2007 15:48 GMT
I have an ASP.net 2.0 website. This website have a module; Public Module
myModule.
Is all the data in this module shared and not thread safe?

I would like explicitly create a shared object in an asp.net web page;
private shared lockkey string

SyncLock me
lockey = "COBOLCALL"
monitor.enter(lockey)
dosomething()  'calling a single thread dll in cobol
monitor.exit(lockey)
end SyncLock

Would the above code be thread safe?

Arne Garvander
Certified Geek
Professional Data Dude
bruce barker - 14 Sep 2007 16:14 GMT
yes, but you are using two locking techiques at the same time;

the synclock is threadsafe for any threads created during the request,
but not between two requests happening at the same time. this is becuas
the synclock is taken the instance of the request. at diffent request is
 locking a different object.

if lockkey is a privte shared, then monitor lock is threadsafe. not sure
why you assign a value to the lockkey inline as opposed to its constructor.

this assumes that this is the only code that calls the routine.

but you could just as easily use (if i know my vb syntax):

    private shared lockkey as string = ""

    synclock lockkey
        dosomething
    end synclock

-- bruce (sqlwork.com)

> I have an ASP.net 2.0 website. This website have a module; Public Module
> myModule.
[quoted text clipped - 15 lines]
> Certified Geek
> Professional Data Dude

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.