0

The injectable service is actually working like this:

public event Action<TValue1, TValue2, TValue3> OnAddChange;
public void AddReport(TValue1 var1, TValue2 var2, TValue3 var3)
{
    NotifyAddChanged(var1, var2, var3);
}
private void NotifyAddChanged(TValue1 var1, TValue2 var2, TValue3 var3)
{
    OnAddChange?.Invoke(var1, var2, var3);
}

And the consumer goes like this:

protected override void OnInitialized()
{
    MyService.OnAddChange+= addToList;
}

public void Dispose()
{
    MyService.OnAddChange -= addToList;
}

private void addToList(TValue1 variable1, TValue2 variable2, TValue3 variable3)
{
}

But I came to a point where my event must be asynchronous. I tried different approach like public Task event Action<TValue1, TValue2, TValue3> OnAddChange;, but it isn't working. So, how can I make it asynchronous?

user3856437
  • 2,071
  • 4
  • 22
  • 27
  • 1
    Specify how and why you 'need it async', maybe this should be reopened. – H H May 19 '20 at 11:59
  • As a side note, the name `OnAddChange` [is not suitable for an event](https://stackoverflow.com/questions/724085/events-naming-convention-and-style). The `On` prefix is generally reserved for the `protected virtual` method that raises the event. – Theodor Zoulias May 19 '20 at 14:07
  • Check this out: [How do I await events in C#?](https://stackoverflow.com/questions/27761852/how-do-i-await-events-in-c) You probably need to declare the event as `public event Func AddChange`. – Theodor Zoulias May 19 '20 at 14:12

0 Answers0