/// <summary>
/// Initializes a new instance of the <see cref="DelayedInvoke"/> class.
/// </summary>
/// <param name="action">The action to perform.</param>
/// <param name="timeout">The timeout before running.</param>
/// <param name="blocking">if set to <c>true</c> then the delay will block.</param>
/// <param name="args">The arguments to pass to the action.</param>
public DelayedInvoke(Delegate action, int timeout, bool blocking, object[] args = null)
{
if (timeout == 0)
{
action.DynamicInvoke(args);
}
if (blocking)
{
do
{
Restart = false;
Thread.Sleep(timeout);
} while (Restart);
HasReturned = true;
ReturnValue = action.DynamicInvoke(args);
}
else
{
thread = new Thread(delegate()
{
do
{
Restart = false;
Thread.Sleep(timeout);
} while (Restart);
HasReturned = true;
ReturnValue = action.DynamicInvoke(args);
});
thread.Name = "DelayedInvoke: " + action.Method.Name;
thread.Start();
}
}