當前位置: 首頁>>代碼示例>>C#>>正文


C# EventHandler.DynamicInvoke方法代碼示例

本文整理匯總了C#中EventHandler.DynamicInvoke方法的典型用法代碼示例。如果您正苦於以下問題:C# EventHandler.DynamicInvoke方法的具體用法?C# EventHandler.DynamicInvoke怎麽用?C# EventHandler.DynamicInvoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在EventHandler的用法示例。


在下文中一共展示了EventHandler.DynamicInvoke方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConnectAsync

        public bool ConnectAsync(EventHandler<SocketAsyncEventArgs> onCompletion)
        {
            if (socket.Connected)
            {
                // already connected, just invoke the 'on completion' event.
                onCompletion.DynamicInvoke(null, null);
                return false; // operation not pending - return synchronously
            }
            else
            {

                SocketAsyncEventArgs socketEventArgs = new SocketAsyncEventArgs()
                {
                    RemoteEndPoint = new IPEndPoint(this.hostaddress, this.port)
                };

                socketEventArgs.Completed += onCompletion;

                return socket.ConnectAsync(socketEventArgs);
            }
        }
開發者ID:vstrien,項目名稱:KOCus,代碼行數:21,代碼來源:SocketAsync.cs

示例2: EventFire

        private void EventFire(EventHandler evntHndlr, EventArgs ea)
        {
            if (evntHndlr == null)
                return;

            int i = 0;
            foreach (Delegate del in evntHndlr.GetInvocationList())
            {
                try
                {
                    ISynchronizeInvoke syncr = del.Target as ISynchronizeInvoke;
                    if (syncr == null)
                    {
                        evntHndlr.DynamicInvoke(new object[] { this, ea });
                    }
                    else if (syncr.InvokeRequired)
                    {
                        syncr.Invoke(evntHndlr, new object[] { this, ea });
                    }
                    else
                    {
                        evntHndlr.DynamicInvoke(new object[] { this, ea });
                    }
                }
                catch (Exception ex)
                {
                    //
                    // Eat the exception
                    //
                    Trace.WriteLine(string.Format("SplitButton failed delegate call {0}.  Exception {1}", i, ex.ToString()));
                }

                ++i;
            }
        }
開發者ID:Dason1986,項目名稱:Lib,代碼行數:35,代碼來源:SplitButton.cs

示例3: EventFire

        private void EventFire(EventHandler evntHndlr, EventArgs ea)
        {
            // Make sure that the handler has methods bound to it.
            if (evntHndlr == null)
                return;

            // Iterate through the methods attached to the handler:
            // 1	If an exception is thrown, swallow it
            // 2	Make sure that Contorl-Invoke is used if appropriate.
            int i = 0;
            foreach (Delegate del in evntHndlr.GetInvocationList())
            {
                try
                {
                    //
                    //	syncr is more than likely a control through it could be
                    // any class that supports ISynchronizeInvoke interface
                    //
                    ISynchronizeInvoke syncr = del.Target as ISynchronizeInvoke;
                    if (syncr == null)
                    {
                        //
                        // If del.Target does not represent a control (or a class that
                        // requires synchronization) then invoke the event as usual.
                        //
                        evntHndlr.DynamicInvoke(new object[] { this, ea });
                    }
                    else if (syncr.InvokeRequired)
                    {
                        //
                        // syncr represents a control and invoke is required so
                        // use the syncr's invoke (or Control-invoke).
                        //
                        syncr.Invoke(evntHndlr, new object[] { this, ea });
                    }
                    else
                    {
                        //
                        // syncr represents a control but invoke on the control
                        // is not required.  This means that we are on the UI thread
                        // of that control.
                        //
                        evntHndlr.DynamicInvoke(new object[] { this, ea });
                    }
                }
                catch (Exception ex)
                {
                    //
                    // Eat the exception
                    //
                    System.Diagnostics.Debug.WriteLine(string.Format("SplitButton failed delegate call {0}.  Exception {1}", i, ex.ToString()));
                }

                ++i;
            }
        }
開發者ID:sunpander,項目名稱:VSDT,代碼行數:56,代碼來源:SplitButton.cs


注:本文中的EventHandler.DynamicInvoke方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。