処理に時間がかかるものなら、処理中にアプリ側で実行中なのか分かりづらい。
ボタンを非活性にすると、処理中は「ボタン押せないから処理実行中なんだな」とわかる。
//ボタンを非活性にする
btn.Enabled = false;
//ボタンを活性にする
btn.Enabled = true;
こういう実行処理がある。
try
{
//実行
Controller.実行処理();
//処理完了
Controller.OutPutLog($"処理が完了しました 時刻:{DateTime.Now}");
MessageBox.Show("処理が完了しました", "完了", MessageBoxButtons.OK,MessageBoxIcon.None);
}
catch (Exception ex)//エラー時
{
Controller.OutPutLog($"エラーが発生しました 時刻:{DateTime.Now}\r\n{ex.Message}");
MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
ボタン活性、非活性を入れ込んでみた。
活性処理をfinallyに入れてあげることで、正常、エラー時、のどちらも対応できる
//ボタンを非活性にする
btn.Enabled = false;
try
{
//実行
Controller.実行処理();
//処理完了
Controller.OutPutLog($"処理が完了しました 時刻:{DateTime.Now}");
MessageBox.Show("処理が完了しました", "完了", MessageBoxButtons.OK,MessageBoxIcon.None);
}
catch (Exception ex)//エラー時
{
Controller.OutPutLog($"エラーが発生しました 時刻:{DateTime.Now}\r\n{ex.Message}");
MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
//ボタンを活性にする
btn.Enabled = true;
}