Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6672353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:29:54+00:00 2026-05-26T03:29:54+00:00

I have array of timer.I want timer0 work with 1st dataValue in _dataValues, 2nd

  • 0

I have array of timer.I want timer0 work with 1st dataValue in _dataValues, 2nd timer work with 2nd dataValue in _dataValues, 3rd timer work with 3rd dataValue in _dataValues and etc and also show result in label in windows form.I use System.Windows.Forms.Timer.Here is my code,

void PrepareTimers(List<int> _dataValues)    
{
    int i = 0;

    foreach (int dataValue in _dataValues)
    {
        timerNames[i] ="timer"+ string.Format("{0}", i);
        timer1[i] = new Timer();

        t[i] = dataValue.ToString();
        a[i] = timer1[i].ToString();
        a[i] = t[i];

        timer1[i].Tick += new EventHandler(timer_Tick);
        timer1[i].Interval = (1000) * (1);                   

        label = new Label();
        label.Name = "label_name" + i;
        label.Size = new Size(200, 20);
        label.Location = new Point(45, 100 + i * 30);
        label.TabIndex = i;
        label.Visible = true;
        this.Controls.Add(label);                    

        dict[timer1[i]] = label;
        timer1[i].Enabled = true;
        timer1[i].Start();
        i++;    
    }
}

private void timer_Tick =(object sender, EventArgs e)    
{       
    string myconstring = "SERVER=localhost;" + "DATABASE=alicosms;" + "UID=root;" + "PASSWORD=;";
    MySqlConnection mycon = new MySqlConnection(myconstring);

    i = 0;
    string u = "UPDATED";
    mycon.Open();

    foreach (int dataValue in _dataValues)               
    {                
        if (a[i] == dataValue.ToString())
        {
            MySqlCommand cmd = new MySqlCommand("UPDATE sms_data_bankasia set flag =  " + (dataValue.ToString()) + " *2 , sendingstatus = '" + u + "' WHERE flag = " + dataValue.ToString() + " LIMIT 1", mycon);

            cmd.ExecuteNonQuery();
            Console.WriteLine("row update" + dataValue.ToString());          

            mycon.Close();

            mycon.Open();
            string sql = "SELECT count(flag) FROM sms_data_bankasia where sendingstatus='UPDATED' AND flag = " + (dataValue.ToString()) + " *2 group by flag";
            MySqlCommand comd = mycon.CreateCommand();
            comd.CommandText = sql;
            MySqlDataReader dtr = comd.ExecuteReader();
            try
            {
                while (dtr.Read())
                {
                    Timer t = (Timer)sender;
                    dict[t].Text = dtr[0].ToString() + " program Updated " + dataValue.ToString();                                
                }
                dtr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        i++;
    }
    mycon.Close();
}

But it update 4 row in per sec and every EventHandler work with every dataValue.I want 1st timer update 1 row in 1 sec and show in label that 1row update with 1st dataValue and 2nd timer update 1row in 1 sec and show in another label that 1 row update with 2nd dataValue and so on.What should i do? Any one can help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:29:54+00:00Added an answer on May 26, 2026 at 3:29 am

    In PrepareTimers assign a tag to each timer: timer1[i] = new Timer(); timer1[i].Tag = i;
    Then you can use this in timer_Tick instead of looping through the whole array:

    i = (int)((Timer)sender).Tag;
    int dataValue = _dataValues[i];
    //...
    

    instead of:

    i = 0;
    foreach (int dataValue in _dataValues)
    {
        if (a[i] == dataValue.ToString())
        //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array of image url. I want to show the images into UIImageView.
I have an array an a timer that adds a new object to my
I have an array of 1000-2000 elements which are pointers to objects. I want
I want to be able to do the following: I have an array of
I have an array with times (string) e.g 2:23, 3:2:22 etc. $times = array(2:33,
I have an array, and I want to make a hash so I can
If I have an array like: $b=array(1,6,8,9); and I also have a mysql table
So I want to have an array in a .txt file with separate lines
I have an array of numbers that can be 1-24. ($timelist) I want to
I have an array of ~1200 ruby objects and I want to loop over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.