public static void Execute(Command cmd) { if (cmd.Condition) { if (cmd is CommandAsync) { var command = (cmd as CommandAsync); ListCommands.Add(command); command.OnFinished += (s, e) => ListCommands.Remove(cmd as CommandAsync); command.OnFinished += new EventHandler(OnFinished); command.OnCanceled += new EventHandler(OnCanceled); command.OnError += new EventHandler(OnError); command.Start(); } else if (cmd is Command) { cmd.Execute(); if (OnCommandFinished != null) { OnCommandFinished(null, EventArgs.Empty); } } } else { ViewMainForm.GetInstance.MessageShow(cmd.errorMessage, strings.Info, MessageBoxButtons.OK, MessageBoxIcon.Information); } }