Browse Source

Fixed animation scenario bug

Tig 9 months ago
parent
commit
ed6ae17a14
1 changed files with 23 additions and 20 deletions
  1. 23 20
      UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs

+ 23 - 20
UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs

@@ -70,26 +70,29 @@ public class AnimationScenario : Scenario
 
         imageView.SetImage (Image.Load<Rgba32> (File.ReadAllBytes (f.FullName)));
 
-        Task.Run (
-                  () =>
-                  {
-                      while (!_closed)
-                      {
-                          // When updating from a Thread/Task always use Invoke
-                          Application.Invoke (
-                                              () =>
-                                              {
-                                                  imageView.NextFrame ();
-                                                  imageView.SetNeedsDisplay ();
-                                              }
-                                             );
-
-                          Task.Delay (100).Wait ();
-                      }
-                  }
-                 );
-
-        win.Closing += (sender, args) => _closed = true;
+        win.Initialized += (sender, args) =>
+                           {
+                               Task.Run (
+                                         () =>
+                                         {
+                                             while (!_closed)
+                                             {
+                                                 // When updating from a Thread/Task always use Invoke
+                                                 Application.Invoke (
+                                                                     () =>
+                                                                     {
+                                                                         imageView.NextFrame ();
+                                                                         imageView.SetNeedsDisplay ();
+                                                                     }
+                                                                    );
+
+                                                 Task.Delay (100).Wait ();
+                                             }
+                                         }
+                                        );
+                           };
+
+        Application.NotifyStopRunState += (sender, args) => _closed = true;
 
         _closed = false;
         Application.Run (win);