diff --git a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs index f2dfb2b..c6a6092 100644 --- a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs +++ b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs @@ -1,4 +1,4 @@ -using Capnp.FrameTracing; +using Capnp.FrameTracing; using Capnp.Util; using Microsoft.Extensions.Logging; using System; @@ -10,32 +10,12 @@ using System.Threading.Tasks; namespace Capnp.Rpc { - /// - /// State of Variable has changed - /// - public delegate void StateChanged(); - - /// - /// ConnectionState has changed EventArgs - /// - public class ConnectionStateEventArgs : EventArgs + public class ConnectionStateChange { - /// - /// New State of Connection - /// public ConnectionState NewState { get; set; } - - /// - /// Last State of Connection - /// public ConnectionState LastState { get; set; } } - /// - /// ConnectionState EventHandler - /// - public delegate void ConnectionStateEventHandler(Object sender, ConnectionStateEventArgs e); - /// /// TCP-based RPC implementation which will establish a connection to a TCP server implementing /// the Cap'n Proto RPC protocol. @@ -285,15 +265,7 @@ namespace Capnp.Rpc /// /// State of Connection has changed /// - public event ConnectionStateEventHandler? ConnectionStateChanged; - - /// - /// On ConnectionState changed - /// - protected virtual void OnConnectionStateChanged(ConnectionStateEventArgs e) - { - ConnectionStateChanged?.Invoke(this, e); - } + public event EventHandler ConnectionStateChanged; private ConnectionState _State = ConnectionState.Initializing; @@ -307,14 +279,18 @@ namespace Capnp.Rpc } private set { - ConnectionStateEventArgs args = new ConnectionStateEventArgs() + ConnectionStateChange args = new ConnectionStateChange() { LastState = _State, NewState = value }; _State = value; - OnConnectionStateChanged(args); + EventHandler eventHandler = ConnectionStateChanged; + if(eventHandler != null) + { + eventHandler(this, args); + } } } @@ -350,4 +326,4 @@ namespace Capnp.Rpc /// public bool IsWaitingForData => _pump?.IsWaitingForData ?? false; } -} \ No newline at end of file +}