M
M
Mikhail2017-11-26 14:55:04
WPF
Mikhail, 2017-11-26 14:55:04

Why can't I stop the animation?

Hello. There is a class with two methods:

async public void DisplayAnimation(Canvas canvas)
{
     this.IsShowAnimation = true;
     while (this.IsShowAnimation)
     {
         this.Draw(this.Angle, StartPoint, canvas);
         await Task.Delay(20);
         canvas.Children.Clear();
         this.Angle += 3;
     }
}

public void StopAnimation(Canvas canvas)
{
     this.IsShowAnimation = false;
}

If I call somewhere in the code DisplayAnimation(), then the animation starts to work correctly. But if I call after some time StopAnimation(), then for some reason it continues to work, although, according to my logic, it should stop. What could be the problem?
If anything, then here is a link to the source code
PS All access modifiers are configured correctly. All handlers are correctly called in the code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2017-11-26
@mak_ufo

Give a link in the source code where exactly the code is in the version as given. What I saw in the code and in your example is not the same thing. The source starts and stops the timer. Your example is taken out of context, so it's hard to understand something from it.
I didn’t clone your code from github, but I noticed that ChebyshevMachine is a structure, not a class. I do not know the reason for this choice, but I can assume that this may be the problem. Put a breakpoint on the StopAnimation method and check that this is the same object that you started the timer on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question