Try to avoid using delegates/functions within a foreach loop, and if you do, use a copy of the object, not the variable in the loop statement.
var elementCopy = element;
...
app[i].Click += (sender,evt) => run(elementCopy,dir);
If you use the element directly, there is a chance it will always use the last element in the enumerable for the delegate
Edit: Refer to this: Using the iterator variable of foreach loop in a lambda expression - why fails?
It explains why you should do what I said more in-depth.