修复动画系统因闭包陷阱导致不执行正确TaskControl的错误

This commit is contained in:
ZouJin 2024-08-06 17:41:56 +08:00
parent 2f9bf11318
commit f31f93c52f
3 changed files with 10 additions and 7 deletions

View File

@ -250,7 +250,8 @@ namespace VPet_Simulator.Core
return;
}
nowid = 0;
Control = new TaskControl(EndAction);
var NEWControl = new TaskControl(EndAction);
Control = NEWControl;
parant.Dispatcher.Invoke(() =>
{
parant.Tag = this;
@ -276,7 +277,7 @@ namespace VPet_Simulator.Core
}
t1?.Start();
t2?.Start();
Task.Run(() => Animations[0].Run(FoodGrid.Food, Control));
Task.Run(() => Animations[0].Run(FoodGrid.Food, NEWControl));
});
}
}

View File

@ -265,12 +265,13 @@ namespace VPet_Simulator.Core
return;
}
nowid = 0;
Control = new TaskControl(EndAction);
var NEWControl = new TaskControl(EndAction);
Control = NEWControl;
parant.Dispatcher.Invoke(() =>
{
if (parant.Tag == this)
{
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, Control));
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, NEWControl));
return;
}
System.Windows.Controls.Image img;
@ -304,7 +305,7 @@ namespace VPet_Simulator.Core
parant.Tag = this;
img.Source = new BitmapImage(new Uri(Path));
img.Width = Width;
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, Control));
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, NEWControl));
});
}
/// <summary>

View File

@ -90,7 +90,8 @@ namespace VPet_Simulator.Core
Control.EndAction = EndAction;
return;
}
Control = new TaskControl(EndAction);
var NEWControl = new TaskControl(EndAction);
Control = NEWControl;
parant.Dispatcher.Invoke(() =>
{
@ -127,7 +128,7 @@ namespace VPet_Simulator.Core
img.Source = new BitmapImage(new Uri(Path));
parant.Tag = this;
}
Task.Run(() => Run(Control));
Task.Run(() => Run(NEWControl));
});
}
/// <summary>