Window won't close on Timer Tick with a Delegate

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Hello,

I have a Fade-In window in my application, that is created in a
seperate Thread.
When a certain Event occurs I create a delegate in my Program which
calls a method in my Fade In window.

This method disables a few buttons and sets some variables and then
sets a Timer control to Enabled with an Intervall of 3000.

In the Tick Event of this Timer there is simply the command "Close();"
to close the FadeIn window.

The Tick method however is never called, so the FadeIn never closes,
though the button properties and variables are all set correctly.

Where is the problem here?

TIA,
Patrick
 
hi Patrick.
it sounds like a similar issue posted recently, here is a copy of the reply:

you might be doing invalid cross thread operations. if you debug the client
from within VS you should get an exception raised about this that wouldn't
occur if running from outside VS.
you can check if it is valid to call Close() from the timer_tick event
by first checking if the Form.InvokeRequired property is true. if it is
true, then you need to transfer execution of the function to the UI thread,
like so;

delegate void timer1_TickDelegate(object sender, System.EventArgs e);
private void timer1_Tick(object sender, System.EventArgs e)
{
if(this.InvokeRequired)
{
BeginInvoke(new timer1_TickDelegate(this.timer1_Tick), new
object[]{sender, e});
return;
}

Close();
}

hope this helps
tim
 
Back
Top