Safe method invoker in c#

Today I was reading an article on codeproject by Mark Clifton about using a safe invoker for a method.

While the idea was quite good, I think the implementation was a bit bloated, so I posted a comment with my own implementation.

This was the implementation I posted:

class SafeMethodInvoker

{ public delegate void ExcDlgt(Exception e);public delegate void voidDlgt();

public delegate bool boolDlgt();

public static void Run(boolDlgt del, int TimeOutMs,

ExcDlgt Critical,voidDlgt Failure,voidDlgt Timeout )

{

Thread t = new Thread(delegate() { try { if (!del()) Failure(); } catch (Exception e) { Critical(e); } } );

t.Start();

if (!t.Join(TimeOutMs)) Timeout();

}

}

}

Way shorter as you might see

comments powered by Disqus