Search code examples
timerargumentsc++-clisystem

Pass arguments in ElapsedEventHandler C++/CLI


How do I pass arguments to my function with ElapsedEventHandler?

NewTimer->Elapsed+=gcnew ElapsedEventHandler(&TimerEvent(String1,String2)); ???

I get this error:

'System::Timers::ElapsedEventHandler' : a delegate constructor expects 2 argument(s)

Any help appreciated.


Solution

  • ElapsedEventHandler defines a delegate that takes two parameters:

    • The object that raised the event (the timer object).
    • ElapsedEventArgs, which contains the time that the timer was triggered.

    If you need other information in your event handler, store them in fields on your class, and reference them that way.