Пример #1
0
        /// <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
                try { ControlToInvokeOn.BeginInvoke(new MessengerCallbackFunction(messengerCallbackFunction), (object)command); } catch { }
            }
            else
            {
                //Directly call
                try { messengerCallbackFunction.BeginInvoke(command, null, null); } catch { }
            }
        }
Пример #2
0
        /// <summary> Helper function to Invoke or directly call event. </summary>
        /// <param name="newLineHandler"> The event handler. </param>
        /// <param name="newLineArgs"></param>
        private void InvokeNewLineEvent(EventHandler <CommandEventArgs> newLineHandler, CommandEventArgs newLineArgs)
        {
            if (newLineHandler == null || (ControlToInvokeOn != null && ControlToInvokeOn.IsDisposed))
            {
                return;
            }

            if (ControlToInvokeOn != null)
            {
                //Asynchronously call on UI thread
                try { ControlToInvokeOn.BeginInvoke((MethodInvoker)(() => newLineHandler(this, newLineArgs))); } catch { }
            }
            else
            {
                //Directly call
                try { newLineHandler.BeginInvoke(this, newLineArgs, null, null); } catch { }
            }
        }