public static void TryToRun(Action execute, string onFailMessage) { do { try { execute(); return; } catch (IOException e) { Alerts.Error(e.Message); Console.Clear(); } } while (MessageBox.Show(onFailMessage) == MessageBox.MessageBoxResult.Yes); }
public static bool TryToRun(Action <SqlConnection> execute, string onFailMessage) { do { try { using (SqlConnection dbcon = new SqlConnection(ConnectionSettings.Instance.ConnectionString)) { dbcon.Open(); execute(dbcon); return(true); } } catch (SqlException e) { Alerts.Error(e.Message); Console.Clear(); } } while (MessageBox.Show(onFailMessage) == MessageBox.MessageBoxResult.Yes); return(false); }