本文整理匯總了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);
}
}
示例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;
}
}
示例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;
}
}