question

AndrewFraserTDK-7346 avatar image
0 Votes"
AndrewFraserTDK-7346 asked DavidLowndes-6766 commented

WinForm Timers not firing

I have an application that has been running for the last couple of years without problem.
I had reason to make some additions to the application recently and it completely stopped working.
On closer investigation, NONE of the timers that I have dropped onto my main application form are firing even after setting their Enabled property to true !
My application uses half a dozen timers on the form for different tasks and none of them are now working.
I have no explanation as to why this is happening other than suspecting that a .NET Framework update broke something but there does not seem to be any 'noise' on the internet suggesting no one else has this issue.

Does anyone have any thoughts what might be happening ?

Andy

dotnet-csharpwindows-formsdotnet-runtime
· 19
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you create a new project as a sanity test, can you reproduce the problem?

0 Votes 0 ·

David,

Thanks for your quick reply.
Yes, if I create a new project the timer works as expected.
But if I drop a new timer on my exiting applications main form, set it to enabled by default and put a breakpoint on the timer tick method, it does not get called !
It is quite bizarre !

Andy

0 Votes 0 ·

Okay, this must be something I have done - though I can't think what I could do to kill all timers on my form but...
The timer handler is called once but after I initialise my application never again so something I do somewhere seems to have killed the timers.
What I don't understand is all their Enabled properties are set to true and their intervals are not messed up so I am at a bit of a loss :-(

Will need to dig deeper into my initialisation code !

Andy

0 Votes 0 ·

Okay, this gets stranger !
In my initialisation code, I load the customers logo from the embedded resource.

 this._customerLogo = this.LoadImageFromEmbeddedResource( "logo.png" );

LoadImageFromEmbeddedResource looks like this:

 private Image LoadImageFromEmbeddedResource( string rscname )
 {
     System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
    
     System.IO.Stream file = thisExe.GetManifestResourceStream("App.Images." + rscname);
    
     return Image.FromStream( file );
 }

If I comment out the this._customerLogo, the timer keeps firing and if I put that line back in, the timer stops firing after this code is called !

If anyone can explain this I would be delighted to hear it !

Andy

0 Votes 0 ·

I can't imagine why that should have an effect, but do you need a using on that Stream object?

0 Votes 0 ·

David,

Good point, I guess the stream will not be disposed when the method exits.
Unfortunately, putting the stream into a using statement does not fix my timer issue :-(

Thanks for your comments though - very much appreciated.

Andy

0 Votes 0 ·
Show more comments
Viorel-1 avatar image Viorel-1 AndrewFraserTDK-7346 ·

Does it succeed (without throwing an uncaught exception)?

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 AndrewFraserTDK-7346 ·

Does it work if you comment this._customerLogo, but still call LoadImageFromEmbeddedResource, and then also comment some of its lines?

0 Votes 0 ·

Good shout !
If I call LoadImageFromEmbeddedResource but don't load the return value into _customerLogo, the time keeps firing :-)
_customerLogo is defined as:

 /// <summary>
 /// The logo that is displayed on the ribbon bar.
 /// </summary>
 private readonly Image _customerLogo;

Andy



0 Votes 0 ·
Show more comments

Yes, it does succeed as I see my customer logo on screen.

Thanks.

Andy

0 Votes 0 ·
Show more comments

1 Answer

AndrewFraserTDK-7346 avatar image
1 Vote"
AndrewFraserTDK-7346 answered DavidLowndes-6766 commented

Solved !
It turns out I had carelessly called Refresh on my ribbon bar control within the ribbon bar paint handler that causing recursive paint messages to be generated.
If I had followed David's suggestion to use Spy++ might have seen all these messages flying about !
Surprised this did not cause additional problems.

Thanks to both of you for your suggestions - much appreciated.

Andy

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad you've got there in the end. :)

0 Votes 0 ·