为超长时间的循环动画提供新线程以避免stackoverflow

This commit is contained in:
ZouJin 2024-04-23 15:01:27 +08:00
parent d3a72367bc
commit 30e6193d41
3 changed files with 12 additions and 2 deletions

View File

@ -176,7 +176,12 @@ namespace VPet_Simulator.Core
case TaskControl.ControlType.Continue:
if (++parent.nowid >= parent.Animations.Count)
if (parent.IsLoop)
{
parent.nowid = 0;
//让循环动画重新开始立线程,不stackoverflow
Task.Run(() => parent.Animations[0].Run(This, Control));
return;
}
else if (Control.Type == TaskControl.ControlType.Continue)
{
Control.Type = TaskControl.ControlType.Status_Quo;

View File

@ -202,7 +202,12 @@ namespace VPet_Simulator.Core
case TaskControl.ControlType.Continue:
if (++parent.nowid >= parent.Animations.Count)
if (parent.IsLoop)
{
parent.nowid = 0;
//让循环动画重新开始立线程,不stackoverflow
Task.Run(() => parent.Animations[0].Run(This, Control));
return;
}
else if (Control.Type == TaskControl.ControlType.Continue)
{
Control.Type = TaskControl.ControlType.Status_Quo;
@ -303,7 +308,7 @@ namespace VPet_Simulator.Core
if (img.Tag == this)
{
return new Task(() => Animations[0].Run(img, Control));
}
}
img.Tag = this;
img.Source = new BitmapImage(new Uri(Path));
img.Width = Width;

View File

@ -146,7 +146,7 @@ namespace VPet_Simulator.Core
case TaskControl.ControlType.Status_Quo:
if (IsLoop)
{
Run(Control);
Task.Run(() => Run(Control));
}
else
{