I'm trying to show a message box when pressing a button on a winforms application, but the MessageBox hangs and never returns a value.
private void btnApply_Click(object sender, EventArgs e)
{
bool current = false;
if (cmbEmergencyLandingMode.SelectedIndex > 0)
{
if (m_WantedData != false)
{
DialogResult dr = MessageBox.Show("Are you sure you want to enable Emergency Landing mode?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
//i never get to this point
current = (dr == DialogResult.Yes);
}
}
if (m_WantedData == current)
{
//do something
}
else if (m_WantedData != null)
{
//do something else
}
}
Edit: Ok so i got it to work by handling the button event on a background worker:
private void btnApply_Click(object sender, EventArgs e)
{
if (!bwApply.IsBusy)
bwApply.RunWorkerAsync(cmbEmergencyLandingMode.SelectedIndex);
}
void bwApply_DoWork(object sender, DoWorkEventArgs e)
{
bool current = false;
int selectedIndex = (int)e.Argument;
if (selectedIndex > 0)
{
if (m_WantedData != false)
{
DialogResult dr = MessageBox.Show(
"Are you sure you want to enable Emergency Landing mode?",
"Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
current = (dr == DialogResult.Yes);
}
}
if (m_WantedData == current)
{
//do something
}
else if (m_WantedData != null)
{
//do something else
}
}
thanks to everyone who helped!