本文整理汇总了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;
}
}