Author: | from stackoverflow |
---|---|
Mode: | c# |
Date: | Mon, 11 Jul 2011 17:48:57 |
static bool DoWithTimeout(Action action, int timeout) { EventWaitHandle waitHandle = new EventWaitHandle (false, EventResetMode.ManualReset); AsyncCallback callback = ar => waitHandle.Set(); action.BeginInvoke( callback, null ); return (waitHandle.WaitOne( timeout )); }