本文整理汇总了C#中EventHandler.GetInvocationList方法的典型用法代码示例。如果您正苦于以下问题:C# EventHandler.GetInvocationList方法的具体用法?C# EventHandler.GetInvocationList怎么用?C# EventHandler.GetInvocationList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventHandler
的用法示例。
在下文中一共展示了EventHandler.GetInvocationList方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
AsyncMethodCall test = new AsyncMethodCall();
// Show the main thread id
Console.WriteLine("The main thread is: {0}", Thread.CurrentThread.ManagedThreadId);
// Register Method1 and Method2 into event
OnEvent += new EventHandler<EventArgs>(test.Method1);
OnEvent += new EventHandler<EventArgs>(test.Method2);
// Call event handler methods asynchronize
//Get the multicase delegates of event
Delegate[] delegAry = OnEvent.GetInvocationList();
//loop the delegates list
foreach(EventHandler<EventArgs> deleg in delegAry)
{
deleg.BeginInvoke(null, EventArgs.Empty, null, null);
}
OnEvent -= new EventHandler<EventArgs>(test.Method1);
OnEvent -= new EventHandler<EventArgs>(test.Method2);
Console.ReadKey();
}
示例2: GetInvocationListLength
private int GetInvocationListLength(EventHandler @event)
{
if( @event == null )
{
return 0;
}
return @event.GetInvocationList().Length;
}
示例3: SafeEventSubscribe
/* EVENTS */
private void SafeEventSubscribe(ref EventHandler ev, EventHandler dg)
{
if (ev != null)
foreach (Delegate current in ev.GetInvocationList())
if (current.Target == dg.Target)
return;
ev += dg;
}
示例4: NotifyPageEvent
private void NotifyPageEvent(String key, String title, EventHandler handler)
{
if (handler != null)
{
Delegate[] delegates = handler.GetInvocationList();
foreach (EventHandler item in delegates)
{
try
{
item.Invoke(key, EventArgs.Empty);
}
catch (Exception ex)
{
PageLogger.RecordErrorLog(title, ex);
}
}
}
}
示例5: ProcessCancelableEvent
private bool ProcessCancelableEvent(EventHandler<CCIMEKeybardEventArgs> handler, CCIMEKeybardEventArgs eventArgs)
{
var canceled = false;
Delegate inFocusDelegate = null;
var sender = TextFieldInFocus;
foreach (var instantHandler in handler.GetInvocationList())
{
if (eventArgs.Cancel)
{
break;
}
// Make sure we process all event handlers except for our focused text field
// We need to process it at the end to give the other event handlers a chance
// to cancel the event from propogating to our focused text field.
if (instantHandler.Target == sender)
inFocusDelegate = instantHandler;
else
instantHandler.DynamicInvoke(sender, eventArgs);
}
canceled = eventArgs.Cancel;
if (inFocusDelegate != null && !canceled)
inFocusDelegate.DynamicInvoke(sender, eventArgs);
return canceled;
}
示例6: TriggerAnEvent
private void TriggerAnEvent(EventHandler EH)
{
if (EH == null) return;
var EventListeners = EH.GetInvocationList();
if (EventListeners != null)
{
for (int index = 0; index < EventListeners.Count(); index++)
{
var methodToInvoke = (EventHandler)EventListeners[index];
methodToInvoke.BeginInvoke(this, EventArgs.Empty, EndAsyncEvent, new object[] { });
}
}
}
示例7: 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;
}
}
示例8: 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;
}
}
示例9: FireEvent
/// <summary>
/// Helper method to fire events in a thread safe manner.
/// </summary>
/// <remarks>
/// Checks whether subscribers implement <see cref="System.ComponentModel.ISyncronizeInvoke"/> to ensure we raise the
/// event on the correct thread.
/// </remarks>
/// <param name="mainHandler">The <see cref="System.EventHandler"/> for the event to be raised.</param>
/// <param name="e">An <see cref="System.EventArgs"/> to be passed with the event invocation.</param>
private void FireEvent(EventHandler mainHandler, EventArgs e)
{
// Make sure we have some subscribers
if (mainHandler != null)
{
// Get each subscriber in turn
foreach (EventHandler handler in mainHandler.GetInvocationList())
{
// Get the object containing the subscribing method
// If the target doesn't implement ISyncronizeInvoke, this will be null
ISynchronizeInvoke sync = handler.Target as ISynchronizeInvoke;
// Check if our target requires an Invoke
if (sync != null && sync.InvokeRequired)
{
// Yes it does, so invoke the handler using the target's BeginInvoke method, but wait for it to finish
// This is preferable to using Invoke so that if an exception is thrown its presented
// in the context of the handler, not the current thread
IAsyncResult result = sync.BeginInvoke(handler, new object[] { this, e });
sync.EndInvoke(result);
}
else
{
// No it doesn't, so invoke the handler directly
handler(this, e);
}
}
}
}
示例10: RaiseEvent
private void RaiseEvent(EventHandler<BackgroundParserEventArgs> handler, BackgroundParserEventArgs args)
{
if (handler == null)
return;
foreach (EventHandler<BackgroundParserEventArgs> h in handler.GetInvocationList())
{
args.CancellationToken.ThrowIfCancellationRequested();
h(this, args);
}
}
示例11: AddHandler
/// <summary>
/// Add a handler for the given source's event.
/// </summary>
public static void AddHandler(object source, EventHandler<ValueChangedEventArgs> handler, PropertyDescriptor pd)
{
if (handler == null)
throw new ArgumentNullException("handler");
if (handler.GetInvocationList().Length != 1)
throw new NotSupportedException(SR.Get(SRID.NoMulticastHandlers));
CurrentManager.PrivateAddHandler(source, handler, pd);
}
示例12: Execute
static bool Execute(EventHandler<EditingManagerEventArgs> d)
{
if(d == null) return false;
EditingManagerEventArgs e = new EditingManagerEventArgs();
Delegate[] delegates = d.GetInvocationList();
foreach(EventHandler<EditingManagerEventArgs> dg in delegates)
{
dg(null, e);
if(e.Handled)
return true;
}
return false;
}
示例13: MainFrm_Load
private void MainFrm_Load(object sender, EventArgs e)
{
output("01-27-4版本这是");
//设置当前交易日
GPUtil.setTodayTranDay();
//加载计划
//TranApi.loadTranPlan();
//财务初始化用
codeList = HisDataAPI.getLoadCwInfoCodes();
//全量股票列表
GPUtil.codes = HisDataAPI.getGpCodesFromDb();
//将Method1和Method2注册到事件中
gpOnEvent += new EventHandler<EventArgs>(getYwNewHander);
gpOnEvent += new EventHandler<EventArgs>(gpBuysTransHander);
gpOnEvent += new EventHandler<EventArgs>(gpSellsTransHander);
gpDelegates = gpOnEvent.GetInvocationList();
output("初始化数据开始..");
//初始化股票信息
HisDataAPI.saveTodayHisDataFromSina();
//初始化下外汇
HisDataAPI.refreshRMBLast();
//关键字
KeyWordAPI.loadKeyWord();
QuShi.qsz = QuShi.getQuShiFS();
output("趋势值:" + QuShi.qsz);
//更新到买入队列
StaUtil.add_buys_codes();
StaUtil.add_sells_codes();
}
示例14: OnEvent
protected virtual void OnEvent(EventHandler<PackageEventArgs> handler, PackageEventArgs e)
{
if (handler != null)
{
foreach (EventHandler<PackageEventArgs> singleCast in handler.GetInvocationList())
{
ISynchronizeInvoke syncInvoke = singleCast.Target as ISynchronizeInvoke;
try
{
//This code is to make the raising of the event threadsafe with the UI thread.
if (syncInvoke != null && syncInvoke.InvokeRequired)
{
syncInvoke.BeginInvoke(singleCast, new object[] { this, e });
}
else
{
_log.InfoFormat("Invoking event {0}", singleCast.Method.Name);
singleCast(this, e);
}
}
catch (Exception ex)
{
if (CrashOnException)
{
throw new PacketProcessingException(ex);
}
else
{
if (e != null)
{
RaiseExceptionEncountered(ex, e.ID);
}
else
{
RaiseExceptionEncountered(ex, Guid.Empty);
}
}
}
}
}
}