Safe method invoker in c#

by Tom 27. June 2007 01:04

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

Bookmark and Share

Tags: , ,

Development

About me

Tom Janssens op LinkedIn

Tom Janssens op twitter

Core bvba RSS

My name is Tom Janssens and I am the owner of Core bvba, a software and consultancy company.
I am married to Liesbeth and have 2 sons named Quinten and Matisse.
ICT is both my job and passion.
Next to this my other hobby is actively playing music (mostly guitar), and I am also a lousy poker player.

I am also the founder of the following LinkedIn groups:
BDD Professional
Asp.Net MVC professional

More info about me and my company...