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. General Programming
  3. Visual Basic
  4. Object synchronization method was called from an unsynchronized block of code.

Object synchronization method was called from an unsynchronized block of code.

Scheduled Pinned Locked Moved Visual Basic
graphicsdebugginghelpquestion
2 Posts 1 Posters 4 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.
  • R Offline
    R Offline
    RJGCarey
    wrote on last edited by
    #1

    The following code throws the error above. Module Base Public sub Clock Do If needsNewChart = True Draw = New clsDraw("clock", i_id, True) thdWorkerSub = New Thread(AddressOf Draw.DoIt) thdWorkerSub.Name = "Draw" thdWorkerSub.Start() thdWorkerSub.Join() Draw = Nothing End If Thread.Sleep(100) Loop End Sub End Module Public Class clsDraw Public Sub DoIt '491 lines of code that creates a new bitMap(theBmp) and draws a stock market "tick chart". 'There are two uses of Monitor.Enter > Monitor.Exit on other objects without difficulties in this code. Try lockedGraphics = Monitor.TryEnter(theFrm.bmpTicks, 50) If lockedGraphics = True Then theFrm.bmpTicks = theBmp End If If lockedGraphics = True Then Monitor.Exit(theFrm.bmpTicks) End If Thread.Sleep(10) theFrm.pbTicks.Invalidate() Catch ex As Exception Ers.Show(c_id & "theTks.Draw.DoIt-setdown2", ex) End Try End Sub End Class Monitor.Exit(theFrm.bmpTicks) throws the error. When you step through the code in the debugger, the lock is acquired and the bitmap is copied. I use Monitor to synchronize my threads in many programs that work together to track the stock market. I have not encountered this error before. Why is it occuring? Thanks. RCarey

    RCarey

    R 1 Reply Last reply
    0
    • R RJGCarey

      The following code throws the error above. Module Base Public sub Clock Do If needsNewChart = True Draw = New clsDraw("clock", i_id, True) thdWorkerSub = New Thread(AddressOf Draw.DoIt) thdWorkerSub.Name = "Draw" thdWorkerSub.Start() thdWorkerSub.Join() Draw = Nothing End If Thread.Sleep(100) Loop End Sub End Module Public Class clsDraw Public Sub DoIt '491 lines of code that creates a new bitMap(theBmp) and draws a stock market "tick chart". 'There are two uses of Monitor.Enter > Monitor.Exit on other objects without difficulties in this code. Try lockedGraphics = Monitor.TryEnter(theFrm.bmpTicks, 50) If lockedGraphics = True Then theFrm.bmpTicks = theBmp End If If lockedGraphics = True Then Monitor.Exit(theFrm.bmpTicks) End If Thread.Sleep(10) theFrm.pbTicks.Invalidate() Catch ex As Exception Ers.Show(c_id & "theTks.Draw.DoIt-setdown2", ex) End Try End Sub End Class Monitor.Exit(theFrm.bmpTicks) throws the error. When you step through the code in the debugger, the lock is acquired and the bitmap is copied. I use Monitor to synchronize my threads in many programs that work together to track the stock market. I have not encountered this error before. Why is it occuring? Thanks. RCarey

      RCarey

      R Offline
      R Offline
      RJGCarey
      wrote on last edited by
      #2

      Whoops! Solved the problem. My code changed the object that I had a lock on. Monitor looses track of which object has the lock. Exit tries to unlock the new bitmap which does not have a lock and then throws the error. The solution is to create a seperate locking object for monitor to lock, then change the bitmap, and unlock the object. Other procedures use the locking object also. Works. Thanks RCarey

      RCarey

      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