Windows.Forms.Timer hangs cpu to 100%

  • Thread starter Thread starter alexl
  • Start date Start date
A

alexl

Hello,
I am working on a big project with multiple work threads and one UI
thread,
In the UI thread i have some forms that use timers.
After a time of working on the application it hangs in 100% cpu.
the timer is used as a switch when an operation is needed meaning when
a button is clicked the operations occurs some time after the click.
When I debug it and see where it hangs it seems to hang on the setter
of the enabled property of the timer (m_timer.Enabled = false) . I
tried a workaround where i don't set the timer enabled but use a flag
but then it gets stuck on the ctor of the timer.
Did any1 got any problems like that and maybe solved them?? I'm
desperate here.... please help asap

thanks in advance
Alex
 
When writing a program that has mutiple simultaneous threads, you need to
lock objects with "critial sections" if it is possible that one thread will
try to access an object at the same time another thread is trying to access
the object. In VB.NET you would do something like

Synclock theObjectToLock
theObjectToLock.callAMethod()
End Synclock

What this essentially does is the .NET framework, at runtime, will mark that
object as synchronized, and if another thread attempts to aquire a synclock
on that same object before the previous synclock block has completed, that
thread will block until the synclock is released. If your code does not
correctly use critical sections, you may often run into 100% cpu conditions
very unpredictably.
 
Back
Top