Hello,
I am trying to get a messagebox to "click" the enter key if left open for a a specified amount of time.
I can do this (of a fashion) by using a timer, but the issue is that if there IS user input within the time frame, the key is still"pushed" by the timer (NB: this should not be an issue as there is nothing else on the app that the enter key should effect.
Because its neater, and to err on the side of caution, I am trying to get backgroundworker to do it instead, but I cannot get ti to fire/execute.
Would someone here be able to look at my code and point out what I am/could be doing wrong ?
Thank you.
I am trying to get a messagebox to "click" the enter key if left open for a a specified amount of time.
I can do this (of a fashion) by using a timer, but the issue is that if there IS user input within the time frame, the key is still"pushed" by the timer (NB: this should not be an issue as there is nothing else on the app that the enter key should effect.
Because its neater, and to err on the side of caution, I am trying to get backgroundworker to do it instead, but I cannot get ti to fire/execute.
Would someone here be able to look at my code and point out what I am/could be doing wrong ?
C#:
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
SendKeys.Send("{ENTER}"); // SendWait as alternative
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//timer1.Interval = 10000;
//timer1.Enabled = true;
backgroundWorker1.RunWorkerAsync();
if (MessageBox.Show("Are you sure you want to close?", "Leave ? ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Thread.Sleep(5000);
SendKeys.Send("{ENTER}"); //or Esc
}
Thank you.