I’m using a BackGroundWorker to avoid UI freezing while working with a method which uses wait handles, and this method is used to draw on a panel in the UI and has panel invalidation inside.
something()
{
draw()
panel.invalidate()
A.waitone(500)
}
The problem is, sometimes the Worker gets stuck in the middle of the drawing and when I re press the worker start button it works again and doesn’t get stuck, that means it wasn’t stuck due to being busy, so the drawing which got stuck not the Worker, but I have invalidation after each draw, so any ideas??
If you want the background process to update the UI, you need to use the control’s “Invoke” method (this will ensure that the code is run in the UI thread, and not in the background thread):
Or, without the Lambda
EDIT: after seeing new comment on other answer — you could wrap each an every control call in an ‘Invoke’ call during your threaded processing, so instead of calling the ‘draw()’ method itself in the invoke, have the draw() method use the Invoke whenever it needs to update the UI.