my question is how can i send some arguments in Dispatchertimer.Tick event here is the code: what i wanted to is receive a integer value at dispatcheTimer_Tick
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
//.Text = DateTime.Now.Second.ToString();
}
what i wanted to do is something like this
private void dispatcherTimer_Tick(object sender, EventArgs e,int a)
{
//.Text = DateTime.Now.Second.ToString();
}
how to send a value from a calling point??
While there are a number of ways, I find it most convenient to use anonymous methods to close over variables when doing this:
If you have a handful of lines you could also do something more like:
If you have more than just a handful of lines then you probably still want another method, but you can use a lambda to call that method:
This is convenient for both ignoring parameters of the event handler's delegate when you don't need them (I almost never use
sender
, I pass the actual object myself if I need it so that it's not cast toobject
first.) as well as adding in additional local variables.If you know
a
at the time you're attaching the event handler, you can do something like this: