Questions about argument passing by ref

In reply to peterjin:

Your problem is the same as your last question. You have a task with a static lifetime, and the second call to trigger overwrites the arguments to the first call. The order of the calls is a race condition. Changing the task to automatic gives you the behavior I think you are looking for.

Your change to a ref argument should be a compiler error because tasks with static lifetimes are not allowed to have ref arguments. You are supposed to have access to static arguments from outside the task, like any other static variable.

In any case, passing event and class variables by reference creates a unnecessary double reference.