/// <summary> Helper function to Invoke or directly call callback function. </summary>
 /// <param name="messengerCallbackFunction"> The messenger callback function. </param>
 /// <param name="command">                   The command. </param>
 private void InvokeCallBack(MessengerCallbackFunction messengerCallbackFunction, ReceivedCommand command)
 {
     if (messengerCallbackFunction != null)
     {
         if (_controlToInvokeOn != null && _controlToInvokeOn.InvokeRequired)
         {
             //Asynchronously call on UI thread
             _controlToInvokeOn.Invoke(new MessengerCallbackFunction(messengerCallbackFunction), (object) command);
         }
         else
         {
             //Directly call
             messengerCallbackFunction(command);
         }
     }
 }
 /// <summary> Attaches default callback for certain Message ID. </summary>
 /// <param name="messageId">   Command ID. </param>
 /// <param name="newFunction"> The callback function. </param>
 public void Attach(int messageId, MessengerCallbackFunction newFunction)
 {
     _callbackList[messageId] = newFunction;
 }
        /// <summary> Helper function to Invoke or directly call callback function. </summary>
        /// <param name="messengerCallbackFunction"> The messenger callback function. </param>
        /// <param name="command">                   The command. </param>
        private void InvokeCallBack(MessengerCallbackFunction messengerCallbackFunction, ReceivedCommand command)
        {
            if (messengerCallbackFunction == null || (ControlToInvokeOn != null && ControlToInvokeOn.IsDisposed)) return;

            if (ControlToInvokeOn != null)
            {
                //Asynchronously call on UI thread
                ControlToInvokeOn.BeginInvoke(new MessengerCallbackFunction(messengerCallbackFunction), (object)command);
            }
            else
            {
                //Directly call
                messengerCallbackFunction(command);
            }
        }
 /// <summary> Attaches default callback for unsupported commands. </summary>
 /// <param name="newFunction"> The callback function. </param>
 public void Attach(MessengerCallbackFunction newFunction)
 {
     _defaultCallback = newFunction;
 }
        /// <summary> Helper function to Invoke or directly call callback function. </summary>
        /// <param name="messengerCallbackFunction"> The messenger callback function. </param>
        /// <param name="command">                   The command. </param>
        private void InvokeCallBack(MessengerCallbackFunction messengerCallbackFunction, ReceivedCommand command)
        {
            if (messengerCallbackFunction == null) return;

            //Directly call
            messengerCallbackFunction(command);
        }