OneMoreVladimir
OneMoreVladimir

Reputation: 1673

wpf image repaint in a loop

Good evening residents =) I'm drawing and then calling sleep in a cycle, but image control displays only the last instance of my painting and only when i exit the loop. What should be done to fix it? A piece of code:

while (true)
{
    ...
    if (TMax < T || TMin < T)
    {
        break;
    }
    UpdatePoints();
    ...
    System.Threading.Thread.Sleep(500);
}

private void UpdatePoints()
{
    DrawingVisual dv = new DrawingVisual();
    using (DrawingContext dc = dv.RenderOpen())
    {
        ...
        dc.Close();
    }
    RenderTargetBitmap rtb = new RenderTargetBitmap(1000, 1000, 96, 96,    PixelFormats.Pbgra32);
    rtb.Render(dv);
    critPoints.Source = rtb;
}

Upvotes: 2

Views: 529

Answers (1)

Alexander Molodih
Alexander Molodih

Reputation: 1936

Create timer and use timer action to draw your picture, it doesn't work because your thread doesn't release when you use Sleep method, it is also interop your self and can't continue execution you program and repaint.

Upvotes: 1

Related Questions