© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•9mo ago•
13 replies
DannyRoastBeef㊙

✅ I need some clarification regarding events and class communication.

Hi guys. I've got a class in a project which fires an event in a simple service I've created so it can be subscribed to inside another unrelated class. Here's the code:

This is the method in the service which invokes the event handler. I inject this in to both the subscribing class and the one I intend to raise it.
public event EventHandler? OnKanbanCardOrderChanged;
    public void NotifyKanbanCardOrderHasChanged()
    {
        EventHandler? handler = OnKanbanCardOrderChanged;
        handler?.Invoke(this, EventArgs.Empty);
    }
public event EventHandler? OnKanbanCardOrderChanged;
    public void NotifyKanbanCardOrderHasChanged()
    {
        EventHandler? handler = OnKanbanCardOrderChanged;
        handler?.Invoke(this, EventArgs.Empty);
    }


This is the method in the class in which I activate the event:
async void OnCardDeleteConfirmed()
    {
        await _cardDetailsDialog.CloseDialog();
        AppState.NotifyKanbanCardOrderHasChanged();
    }
async void OnCardDeleteConfirmed()
    {
        await _cardDetailsDialog.CloseDialog();
        AppState.NotifyKanbanCardOrderHasChanged();
    }


This is in the class where I'm subscribing to the event:
  protected override async Task OnInitializedAsync()
    {
        AppState.OnKanbanCardOrderChanged += KanbanCard_OnCardDeleted;
    }

 async void KanbanCard_OnCardDeleted(object? sender, EventArgs args)
    {
        Console.WriteLine("EVENT FIRED");
    }
  protected override async Task OnInitializedAsync()
    {
        AppState.OnKanbanCardOrderChanged += KanbanCard_OnCardDeleted;
    }

 async void KanbanCard_OnCardDeleted(object? sender, EventArgs args)
    {
        Console.WriteLine("EVENT FIRED");
    }

Pretty standard and this works fine (I think). But whats the alternatives to this? I've been reading about the Mediator pattern, is that something which would be more fitting in this scenario?

Thanks!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Need help regarding variables and class.
C#CC# / help
3y ago
❔ Need some advise regarding HTTP Request
C#CC# / help
3y ago
Some namespace and class questions..
C#CC# / help
4y ago
✅ hey I need some help!
C#CC# / help
17mo ago