Pergunta

If I check with the debugger inside the sender parameter, I can see my object with all its properties, but how can I access those properties? I have tried MyClass mc = MyClass as sender but it's null.

Here's my timer's tick event:

private void timerP_Tick(object sender, EventArgs e)
{
}

And here is the event that starts my timer:

void class_startTimerEvent(MyClass class)
{
    timerP.Tag = class;

    if (InvokeRequired)
        this.Invoke((MethodInvoker)delegate { timerP.Start(); });
    else
        timerP.Start();
}
Foi útil?

Solução

For a EventHandler that uses the standard implementation the sender parameter is always the object that raises the event, in your case it's the timerP object.

So you can get your MyClass object using

var timer = (Timer) sender;
var myClass = (MyClass) timer.Tag;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top