Aditya Chauhan

Aditya Chauhan

  • NA
  • 102
  • 55.8k

Not Able To Control Timer Control can any one help

Mar 10 2015 2:28 AM
i have made a timer control in main()
{
                  System.Timers.Timer aTimer = new System.Timers.Timer();
                aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                aTimer.Start();
                aTimer.Interval = 1000;
                aTimer.Enabled = true;
}


and call it 
  private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            try
            {
                foreach (System.Int32 i in Enum.GetValues(typeof(Keys)))
                {
                    if (GetAsyncKeyState(i) == -32767)
                    {
                        if (Keys.Control == Control.ModifierKeys) Form1.crtl = 1;
                        if (Keys.K == (Keys)i) Form1.k = 1;
                    }
                    if (Form1.k == 1 && Form1.crtl == 1)
                    {
                        string response = ShowDialog("Password Required: ", "Password");
                        
                        if (response.Equals("###########"))
                        {

                            Form1 frm = new Form1();
                            frm.Show();
                            Form1.k = 0;
                            Form1.crtl = 0;


                        }




                    }
                    else
                    {

                        Form1.k = 0;
                        Form1.crtl = 0;
                    }

                }

            }
            catch (Exception)
            {
            }
            finally
            {

            }
        }





but in this case my show dialog form is open but again and again can any one help for this 

my simple task is after show Dialog my timer will be stop


Answers (7)