performance & threads

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

I have a slider in a dialog where the user can adjust the brightness of an
image. the problem is when the image is large the user cannot pull the
slider easily because everytime the slider changes its value the iamge has
to be recalculated. to disable this annoying behaviour I created an exra
thread with low priority to redraw the image. The problem know is that it is
still slow, if the image is very large one have to wait every millimeter the
slider is pulled.

// this starts my thread
thread = new Thread(new ThreadStart(Runner));
thread.Priority = ThreadPriority.Lowest;
thread.Start();


// this is my threadrunner:
void Runner()
{
lock (this)
{
while (true)
{
this.UpdateImage();
Monitor.Wait(this);
}
}
}

// this gets called when there is a valuechanged event in the slider:
void OnValuesChanged()
{
lock (this)
{
Monitor.Pulse(this);
}
}

Please help me with that! thx in advance!
 
Hi cody,

Why are you using lock(this) in the first place?
What exactly does UpdateImage do?
 
Why are you using lock(this) in the first place?

Because I got an exception that told me that I cannot use Monitor.* in a
context that is not locked.
What exactly does UpdateImage do?

It simply applies a colormatrix to my image and redraws the canvas using
Refresh().
 
Back
Top