Paste: lightweight timeout invoke

Author: from stackoverflow
Mode: c#
Date: Mon, 11 Jul 2011 17:48:57
Plain Text |
	
		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 ));
			
		}

New Annotation

Summary:
Author:
Mode:
Body: