0

I have a list and i want to use this list value to create timer.And also want to use those timer to execute 2 MySql query. Here is my code,

    Timer timer;        
    List<uint> _dataValues = new List<uint>();     

    private void button1_Click(object sender, EventArgs e)
    {
        string myconstring = "SERVER=localhost;" + "DATABASE=alicosms;" + "UID=root;" + "PASSWORD=;";
        MySqlConnection mycon = new MySqlConnection(myconstring);
        string sql = "SELECT flag FROM sms_data_bankasia group by flag";
        MySqlCommand comd = mycon.CreateCommand();
        comd.CommandText = sql;
        mycon.Open();
        MySqlDataReader dtr = comd.ExecuteReader();
        count = 0;          
        while (dtr.Read())
            {                   
                _dataValues.Add(dtr.GetUInt32(0));

            }

        dtr.Close();                                  


    }
    void PrepareTimers(List<uint> dataValues)
    {
        foreach (uint dataValue in _dataValues)
        {
           timer = new Timer(TimerAction, dataValue, 1000, 0);
        }
    }
    void TimerAction(object flag)
    {
        string myconstring = "SERVER=localhost;" + "DATABASE=alicosms;" + "UID=root;" + "PASSWORD=;";
        MySqlConnection mycon = new MySqlConnection(myconstring);
        MySqlCommand cmd = new MySqlCommand("SELECT * FROM sms_data_bankasia WHERE flag = @flag", mycon);
        MySqlParameter param = new MySqlParameter();
        param.ParameterName = "@flag";
        param.Value = flag;
        cmd.Parameters.Add(param);


    }    

In PrepareTimers section provide error.I also want to add another query in "TimerAction".So what to do ?Any one can help me?I am using VS 2005.net and C# language.

sumona
  • 67
  • 1
  • 4
  • 10
  • possible duplicate of [Using timers to query DB table rows with different flag column values](http://stackoverflow.com/questions/7460014/using-timers-to-query-db-table-rows-with-different-flag-column-values) – Saeed Amiri Sep 26 '11 at 07:01
  • what is the error? at the first glance I noticed that on the `PrepareTimers` method, you are not using the parameter `dataValues`, instead you are using `_dataValues` – NaveenBhat Sep 26 '11 at 07:02
  • @saeed that post was not helpful for me – sumona Sep 26 '11 at 07:05
  • @knvn the error was "No overload for method 'Timer' takes '4' arguments" – sumona Sep 26 '11 at 07:07
  • @sumona, you didn't reply on answers (for example for my answer) and you didn't mentioned that what's exactly your problem which can't be done by answers, you should spend time to clarifying, when people trying to help you and spend their time. As I understand currently you want to use VS2005 and my answer is not useful for you but with a little changes you can use it. – Saeed Amiri Sep 26 '11 at 07:10
  • @saeed sorry for that but I add comment what i use instead of var but I could not find any solution.I want that change.Can you help me? – sumona Sep 26 '11 at 07:16

1 Answers1

0

Since your error syas that No overload for method 'Timer' takes '4' arguments, I'm guessing that you are using System.Timers.Timer class, for which there is no constructor which takes 4 arguments.

As per your code, you need to use:

System.Threading.Timer

Edit(as per the comment): In order to overcome from this naming conflict, either you can create an alias for the nemespace like

using ThreadingTimer = System.Threading.Timer;

and use ThreadingTimer or use fully qualified name like:

System.Threading.Timer = new System.Threading.Timer(TimerAction, dataValue, 1000, 0);
NaveenBhat
  • 3,248
  • 4
  • 35
  • 48
  • 'Timer' is an ambiguous reference between 'System.Windows.Forms.Timer' and 'System.Threading.Timer' How can I romove this error @knvn.It provide error in 1st line. – sumona Sep 26 '11 at 07:27
  • 'System.Threading.Timer' is a 'type', which is not valid in the given context.How can remove this error @knvn.it provid error after edited. – sumona Sep 26 '11 at 08:11