Can I use BeginInvoke with a MulticastDelegate?

前端 未结 1 1759
闹比i
闹比i 2021-02-08 08:34

I want to raise a series of events from my library class, but I\'m worried that some event subscribers will be rude and take a long time to process some events, thus blocking th

相关标签:
1条回答
  • 2021-02-08 09:26

    I found a similar question on another site, and of course Jon Skeet had answered it. For my scenario, I chose to raise the event for each subscriber on a separate thread:

    if (packet != null && DataPacketReceived != null)
    {
        var args = new DataPacketEventArgs(packet);
        var receivers = DataPacketReceived.GetInvocationList();
        foreach (EventHandler<DataPacketEventArgs> receiver in receivers)
        {
            receiver.BeginInvoke(this, args, null, null);
        }
    }
    
    0 讨论(0)
提交回复
热议问题