none
How to pass some information to the Timer.ElapsedEventHandler? RRS feed

  • Question

  • I generate multiple timers and want to pass some information to the ElapsedEventHandler of each timers.

    On the event, there are two parapeters, that is, object sender, RoutedEventArgs e.

    Can I use this? if so how can I pass an information?

    If not, is there any other way?

    Wednesday, August 15, 2018 9:32 PM

Answers

All replies

  • See the following code sample.

    http://minddumpcode.blogspot.com/2013/07/c-systemtimers-extending-timer-for.html


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Jeff0803 Thursday, August 16, 2018 3:31 PM
    Wednesday, August 15, 2018 9:42 PM
    Moderator
  • private static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            //get the parameters that we specified.
            int timerID = ((TaskTimer)sender).ID;
            string param1 = ((TaskTimer)sender).Param1;
    
            Console.WriteLine("ID:{0} - {1}", timerID, param1);
        }

    In this event handler, I need to stop timer.

    How do I do?

    Friday, August 17, 2018 12:52 AM