Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Thread locking and ASP.NET [modified]

Thread locking and ASP.NET [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netwinformscomsysadmin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    binarymax
    wrote on last edited by
    #1

    Hi, I have some short questions about locking threads in ASP.NET. Normally I use C# console/winforms but in this case I need to write it in VB for ASP.NET. My questions are there any drawbacks to this code in a high-volume of requests? Is this completely wrong for an ASP.NET application? If so what do you recommend? The purpose here is to lock a timestamp and be sure it is set uniquely throughout all the sessions on the web server:

    Protected Shared TimeStamp As Date
    Protected Shared Sub SetUniqueTimeStamp()
    
        Try
            ' Request the lock, and block until it is obtained.
            Monitor.Enter(TimeStamp)
            ' When the lock is obtained, set the Timestamp.
            TimeStamp = Now
        Finally
            'Guarantee at least 1ms tick for uniqueness
            Thread.Sleep(1)
            ' Ensure that the lock is released.
            Monitor.Exit(TimeStamp)
        End Try
    
    End Sub
    

    This is just an example based on some code I altered from this at MSDN: Monitor.Enter Method[^] Many thanks in advance!

    modified on Tuesday, April 14, 2009 10:02 AM

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups