I have an object that moves. This object is represented by a list of points. The calculation is done in a seperate thread. To draw this point there is a window that has a WriteableBitmap attached. The drawing method looks something like this.
- Clear the WriteableBitmap
- ForEach point draw it to the bitmap
- Call the InvalidateVisual() method of the window trough the window dispatcher
If this is done frequently (every 100ms) the result is a window that flickers. How can i avoid that?
Edit: Sample Code
Code of the drawing component
public void FillColor(Color color)
{
writeableBitmap.Clear(Colors.White);
writeableBitmap.Clear(color);
window.Dispatcher.Invoke(
DispatcherPriority.Render, new Action(() => window.InvalidateVisual()));
}
Clear() set the whole Bitmap to a specific color.
The second thread invokes the drawing.
private void DrawObjectFull()
{
while (true)
{
window.FillColor(Colors.BurlyWood);
Thread.Sleep(100);
}
}
Edit #2: I'm not entirely sure if this is the best approach. In the end i just want to draw a moving object from a to b smoothly.