I’ve seen code like this someplace.
Ideally I’d like a loop like this to accommodate this Func event type.
public static event Func<RecentDirectories, DirectoryInfo, Exception, bool> ContinueOnExceptionEvent;
/// <summary>
/// Determine if the loop should continue on a general exception not already handled
/// in the loop's catch statement.
/// </summary>
/// <param name="dir"></param>
/// <param name="e"></param>
/// <returns>True continues loop, false rethrows the exception</returns>
protected virtual bool TryContinueOnException(DirectoryInfo dir, Exception ex)
{
if (!Aborted) // check if thread aborted before doing event
{
if (null != ContinueOnExceptionEvent)
{
// foreach line doesn't compile because
// ContinueOnExceptionEvent doesn't have a GetEnumerator()
foreach (var e in ContinueOnExceptionEvent)
{
if (e(this, dir, ex))
{
return true;
}
}
}
}
return false;
}
How do I get the foreach to get all the events and iterate on them?
You can access each subscriber by calling
GetInvocationList.