Short description: registering OnClient in AltAsync or Alt registers fine, but when trying to unregister methods still get called when emitting event from clientside.
What happens: OffClient does not unregister event
What should happen: OffClient should unregister event and unregistered method souldn't be called when events are being emitted from clientside
Steps and code to reproduce:
Construct class
Emit events, only one line is being printed Async event called! 0 or sync for sync event
Call finish method, emit events, methods still get called, Async event called! 0 being printed
Version: 3.0-dev16, nugets are updated to their latest versions
When trying to construct class again, two instances of class receive events, and this results in code not working properly
using System;
using System.Threading.Tasks;
using AltV.Net;
using AltV.Net.Async;
public class TestEvents
{
public static int InstanceNumber = 0;
private int _instanceNumber;
private TestEvents()
{
this._instanceNumber = TestEvents.InstanceNumber;
TestEvents.InstanceNumber++;
AltAsync.OnClient<AltCorePlayer, int>("testEventJob:asyncEvent", this.AsyncEvent);
Alt.OnClient<AltCorePlayer, int>("testEventJob:event", this.Event);
}
private async void AsyncEvent(AltCorePlayer player, int n)
{
Console.WriteLine($"Async event called! {this._instanceNumber}");
}
private void Event(AltCorePlayer player, int n)
{
Console.WriteLine($"Sync event called! {this._instanceNumber}");
}
public void Finish()
{
AltAsync.OffClient<AltCorePlayer, int>("testEventJob:asyncEvent", this.AsyncEvent);
Alt.OffClient<AltCorePlayer, int>("testEventJob:event", this.Event);
}
}
}
Next dev update will make the Off functions functional by accepting the return value of the On Functions as second parameter. Using the delegate reference won't work for it since they are transformed internally.
Async event called! 0
or sync for sync eventAsync event called! 0
being printedWhen trying to construct class again, two instances of class receive events, and this results in code not working properly