how to make the timer in windows form application work one by one with button click

Status
Not open for further replies.

hari516

Newbie level 6
Joined
Feb 22, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Mumbai
Activity points
1,394
hi,
I just want to enter the timer duartion of three solenoids in three text boxes and click the button called invert operation.The resultant suppose to be enable the corresponding LED in board till the first text box time duration and then it has to consider second timer duration then have to enable the corresponding LED and so on..Is it possible to do it.Hope i conveyed my idea properly..My problem was when ever i run the invert operation button it will consider the last textbox duration and LED high option.The process has to be sequentail..Can i do it ?? If so give me any suggestion to implement this..

Code:
 private void button1_Click_1(object sender, EventArgs e)//invert button
        {
            int i;
            int[] txtvalue = new int[3];
                                  
            //invert.Enabled = false;
            for (i = 0; i < 2; i++ )
            {
                if (i == 0)
                {
                    try
                    {
                        txtvalue[0] = Convert.ToInt32(textBox1.Text);
                        txtvalue[0] = txtvalue[0] * 1000;
                        PortAccess.Output(888, 254);
                        solenoid1.Enabled = false;
                        Timer timer = new Timer { Interval = txtvalue[0] };
                        timer.Tick += timer1_Tick;
                        timer.Start();
                    }
                    catch (InvalidCastException ex)
                    {
                        throw (ex);
                        MessageBox.Show("Please Enter Numbers between 0-100");
                    }
                }

              
               if (i==1)
            {
                ////for second solenoid
                //try
                //{

                //    txtvalue[1] = Convert.ToInt32(textBox2.Text);
                //    txtvalue[1] = txtvalue[1] * 1000;
                //    solenoid2.Enabled = false;
                //    PortAccess.Output(888, 253);
                //    Timer timer1 = new Timer { Interval = txtvalue[1] };
                //    timer1.Tick += timer1_Tick_1;
                //    timer1.Start();
                //}
                //catch (InvalidCastException ex)
                //{
                //    throw (ex);
                //    MessageBox.Show("Please Enter Numbers between 0-100");
                //}

            }
            }
            ////for third solenoid
            //txtvalue3 = Convert.ToInt32(textBox3.Text);
            //txtvalue3 = txtvalue3 * 1000;
            //solenoid3.Enabled = false;
            //PortAccess.Output(888, 251);
            //Timer timer2 = new Timer { Interval = txtvalue3 };
            //timer2.Tick += timer2_Tick;
            //timer2.Start();


        }
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…