c# event handler is called multiple times when event is raised once

前端 未结 4 1636
-上瘾入骨i
-上瘾入骨i 2021-01-05 04:42

Below is my code, first is where I raise the event and second section is where I consume it in another class. It seems pretty straight forward, but the logs are showing that

4条回答
  •  囚心锁ツ
    2021-01-05 05:30

    Try this, this will unregister any prev subscriber:

    ibSerialPort.OnPacketReceived -= ibSerialPort_OnPacketReceived;   // unregister
    ibSerialPort.OnPacketReceived += ibSerialPort_OnPacketReceived;  //register
    

提交回复
热议问题