Hi all,
I was just wondering, is Graphics.DrawImage()
asynchronous?
I'm struggling with a thread safety issue and can't figure out where the problem is.
if i use the following code in the GUI thread:
protected override void OnPaint(PaintEventArgs e)
{
lock (_bitmapSyncRoot)
{
e.Graphics.DrawImage(_bitmap, _xPos, _yPos);
}
}
And have the following code in a separate thread:
private void RedrawBitmapThread()
{
Bitmap newBitmap = new Bitmap(_width, _height);
// Draw bitmap //
Bitmap oldBitmap = null;
lock (_bitmapSyncRoot)
{
oldBitmap = _bitmap;
_bitmap = newBitmap;
}
if (oldBitmap != null)
{
oldBitmap.Dispose();
}
Invoke(Invalidate);
}
Could that explain an accessviolation exception?
The code is running on a windows mobile 6.1 device with compact framework 3.5.
Edit:
Nevermind, it happens also when the methods get executed in the same thread..