/// <summary> /// Invoked when DarkRift receives a message from the server. /// </summary> /// <param name="sender">The client that received the message.</param> /// <param name="e">The arguments for the event.</param> private void Client_MessageReceived(object sender, MessageReceivedEventArgs e) { //If we're handling multithreading then pass the event to the dispatcher if (invokeFromDispatcher) { if (sniffData) { Main.Log("Message Received: Tag = " + e.Tag + ", SendMode = " + e.SendMode); } // DarkRift will recycle the message inside the event args when this method exits so make a copy now that we control the lifecycle of! Message message = e.GetMessage(); MessageReceivedEventArgs args = MessageReceivedEventArgs.Create(message, e.SendMode); Dispatcher.InvokeAsync( () => { EventHandler <MessageReceivedEventArgs> handler = MessageReceived; if (handler != null) { handler.Invoke(sender, args); } message.Dispose(); args.Dispose(); } ); } else { if (sniffData) { Main.Log("Message Received: Tag = " + e.Tag + ", SendMode = " + e.SendMode); } EventHandler <MessageReceivedEventArgs> handler = MessageReceived; if (handler != null) { handler.Invoke(sender, e); } } }
/// <summary> /// Invoked when DarkRift receives a message from the server. /// </summary> /// <param name="sender">THe client that received the message.</param> /// <param name="e">The arguments for the event.</param> void Client_MessageReceived(object sender, MessageReceivedEventArgs e) { if (sniffData) { Debug.Log("Message Received"); //TODO more information! } // DarkRift will recycle the message inside the event args when this method exits so make a copy now that we control the lifecycle of! Message message = e.GetMessage(); MessageReceivedEventArgs args = MessageReceivedEventArgs.Create(message, e.SendMode); Dispatcher.InvokeAsync( () => { EventHandler <MessageReceivedEventArgs> handler = MessageReceived; if (handler != null) { handler.Invoke(sender, args); } message.Dispose(); args.Dispose(); } ); }