Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# Timer

  • 20-06-2008 12:23PM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    I'm using the below code for when the form loads:
    public Form1()
            {
                InitializeComponent();
                System.Timers.Timer myTimer = new System.Timers.Timer();
                myTimer.Elapsed += new ElapsedEventHandler(sqlQuery);
                myTimer.Interval = 5000;
                myTimer.Start();
            }
    
    Only thing is that the new ElapsedEventHandler(sqlQuery); keeps giving me a warning as below and i can't figure it out!?
    No overload for 'sqlQuery' matches delegate 'System.Timers.ElapsedEventHandler'
    Can anyone help me out here!?


Comments

  • Closed Accounts Posts: 413 ✭✭sobriquet


    What is sqlQuery? The argument to 'new ElapsedEventHandler' should be the name of a method that's defined with ElapsedEventHandlers' signature, something like:
    private void sqlQuery(object sender, ElapsedEventArgs e)
    {
    }
    


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Try giving the sqlQuery function the following args:

    sqlQuery(object source, ElapsedEventArgs e)
    {
    .
    .
    }

    But leave the line
    myTimer.Elapsed += new ElapsedEventHandler(sqlQuery);
    as it is. ie. don't try and pass it source or e.


Advertisement