0
我有一個MessageBox.Show事件,我想也阻止基於計時器的方法在MessageBox保持打開狀態時運行。暫停基於計時器的程序在MessageBox.Show()
這裏是我的代碼(在網絡上更改文件中的位置值每x分鐘):
public void offlineSetTurn()
{
try
{
using (StreamWriter sWriter = new StreamWriter("FileLocation"))
{
sWriter.WriteLine(Variable);
}
}
catch (Exception ex)
{
DialogResult result = MessageBox.Show("Can't find file. Click Okay to try again and Cancel to kill program",MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
offlineSetTurn();
}
else if (result == DialogResult.Cancel)
{
Application.Exit();
}
}
}
我在形式方法被調用這個每三十秒。每隔30秒意味着另一個MessageBox彈出。有沒有辦法用MessageBox暫停應用程序,如果沒有,解決這個問題的最好方法是什麼?如果可能的話,我想避免使用Timer.Stop(),因爲它會重置定時器計數。
我認爲最簡單的解決方案是具有可以從第一假脫機消息的第二非模式窗口。取決於第二個窗口中的用戶輸入,您可以退出或調用'offlineSetTurn()'。 –
啊,這是有道理的。如僅當canConnect()返回true時才添加第二個bool canConnect()方法來調用我前述的offlineSetTurn()方法? – Omniabsence