I'm just starting out on the web and this time I'm having trouble with event handling. I develop with blazor, but this seems like a universally applicable problem.
Where I'm stuck is this. I want to notify the page when I get a message. I had no problem with this when I had one browser screen, but when I test my web with two screens open, the events don't work properly. how do I fix this?
Below is my code.
ServiceInfoReceiveHandler.cs
public event EventHandler<(string contentType, string serverName, string message)> InstallServiceInfoReceived;
...
public void Receive(BasicDeliverEventArgs eventArgs)
{
if (contentType == "SVCMGMT/INSTALL/SVCINFO")
{
InstallServiceInfoReceived?.Invoke(this, (contentType, serverName, message));
...
}
}
I fire the event like this and the receive function is always called whenever a message comes in. It's not a matter of the message not arriving.
page.razor
@inject ServiceInfoReceiveHandler _serviceInfoReceiveHandler
protected override async Task OnInitializedAsync()
{
_serviceInfoReceiveHandler.InstallServiceInfoReceived += OnServiceInfoReceived;
}
private async void OnServiceInfoReceived(object sender, (string contentType, string serverName, string message) e)
{
...
}
The razor page I want the result of is like above, but OnInfoReceived is not called.