Unable to unsubscribe Ticks
BlackFlash5 opened this issue · 1 comments
BlackFlash5 commented
What happened?
Ticks continue to run, even after unsubscribing through:
this.Tick -= this.TickAsync;
// or
this.UnregisterTick(this.TickAsync); // is getting called by "this.Tick -= x" anyways...
Expected result
Ticks should stop running after unsubscribing them.
Reproduction steps
Using the following script on the client
using CitizenFX.Core;
namespace MyCoolResource
{
public class TestBaseScript : BaseScript
{
#region CTOR
public TestBaseScript()
{
this.Tick += this.TickAsync; // same as [Tick], but here for science!
Scheduler.Schedule(this.UnsubscribeAll, 1000); // doesn't unsubscribe ticks :(
}
#endregion
#region Scheduler Actions
private void UnsubscribeAll()
{
Debug.WriteLine("UnsubscribeAll runs!");
this.Tick -= this.TickAttrAsync;
this.Tick -= this.TickAsync;
//this.UnregisterTick(this.TickAttrAsync); // is getting called by "this.Tick -= x" anyways...
//this.UnregisterTick(this.TickAsync); // is getting called by "this.Tick -= x" anyways...
}
#endregion
#region Tick
[Tick]
private async Coroutine TickAttrAsync()
{
Debug.WriteLine("TickAttrAsync runs!");
this.Tick -= this.TickAttrAsync; // doesn't unsubscribe tick :(
await BaseScript.Delay(0);
}
private async Coroutine TickAsync()
{
Debug.WriteLine("TickAsync runs!");
this.Tick -= this.TickAsync; // doesn't unsubscribe tick :(
await BaseScript.Delay(0);
}
#endregion
}
}
returns this log (shortened for readability):
Instantiated instance of script MyCoolResource.TestBaseScript.
TickAsync runs!
TickAttrAsync runs!
TickAsync runs!
TickAttrAsync runs!
...
UnsubscribeAll runs!
TickAsync runs!
TickAttrAsync runs!
TickAsync runs!
TickAttrAsync runs!
...
Importancy
Prerequisite for my project
Specific version
FiveM 6509 / Server 6509 Windows
Extra
No response
thorium-cfx commented
MyCoolResource
😎
Will be fixed in the next update