c# - Pass parameters to timer_Tick event -


i'm wanting pass parameters event timer_tick in c# don't want make them global variables. possible?

i had round , came this:

//where start timer lift1up.enabled = true; lift1up.tick += (sender, args) => lift1up_tick(sender, args, destination, currentfloor); lift1up.start();  private void lift1up_tick(object sender, eventargs e, int dest, int current) {     //my code       } 

many thanks! luke.

yes,but not that. can define class inheriting eventargs

class myeventargs : eventargs {     public int dest { get; set; }     public int current { get; set; } } 

then need manually trigger tick event , pass parameters this:

lift1up_tick(this, new myeventargs { dest = 23, current = 100 }); 

and in tick event can arguments:

private void lift1up_tick(object sender, eventargs e) {     var args = (myeventargs)e;     int dest = args.dest;      } 

i don't know there better way.to (manuel trigger) can add timer.set it's interval write code inside of it's tick event:

lift1up_tick(this, new myeventargs { dest = 23, current = 100 }); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -