0
我有一個事件從事件中刪除委託 - 導致同步問題?
this._sequencer.Completed
兩名代表訂閱了這個
this._sequencer.Completed += OnActivityFinished;
this._sequencer.Completed += OnCarrierReLoaded;
是如下
void OnActivityFinished(object sender, EventArgs e)
{
// Do some activity
this._sequencer.Completed -= OnActivityFinished
}
void OnCarrierReLoaded(object sender, EventArgs e)
{
// Do some activity
this._sequencer.Completed -= OnCarrierReLoaded
}
給出的代表implemnetation
事件中的委託被調用爲異步調用,如下所示。 如果委託從上述事件中被移除,它是否會導致同步問題? 請幫我
void EventHelper::FireAndForget(Delegate^ d, ... array<Object^>^ args)
{
try
{
if (d != nullptr)
{
array<Delegate^>^ delegates = d->GetInvocationList();
for each(Delegate^ delegateMethod in delegates)
{
try
{
DynamicInvokeAsyncProc^ evtDelegate = gcnew DynamicInvokeAsyncProc(this, &EventHelper::OnTriggerEvent);
evtDelegate->BeginInvoke(delegateMethod, args, _dynamicAsyncResult, nullptr); //FIX_DEC_09 Handle Leak
}
catch (Exception^ ex)
{
}
}
}
else
{
}
}
catch (Exception^ e)
{
}
}
void EventHelper::OnTriggerEvent(Delegate^ delegateMethod, array<Object^>^ args)
{
try
{
// Dynamically invokes (late-bound) the method represented by the current delegate.
delegateMethod->DynamicInvoke(args);
}
catch (Exception^ ex)
{
Log(LogMessageType::Error, "EventHelper.OnTriggerEvent", ex->ToString());
}
}