Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a timer using VC# which working seems fine. The problem is that I must show message at the time when timer event handler is called. I found the MessageBox.Show not working. Below is my modified code snippet, in which I simplified the event handler as just showing a message.
My window is a full screen and borderless. It seems the message shown is hiden by window's form.
Why can't MessageBox.Show() doesn't work at timer event handler? How can I do if I would like to prompt something when timer event occurres?

C#
void OnGridTmEvt(object source, ElapsedEventArgs e)
{
    MessageBox.Show("Test end");
}
void createGridTmer()
{
    gridFlashTmer = new System.Timers.Timer();
    gridFlashTmer.Elapsed += new ElapsedEventHandler(OnGridTmEvt);
    gridFlashTmer.Interval = Constants.FLASH_MS_COUNT;
    gridFlashTmer.Enabled = true;
}
Posted
Updated 2-Feb-15 19:09pm
v2

Check below link, this will not only give you detail info about problem but also suggest solutions as well (The link though discuss console application but you may do the same in your application as well)

Message box in front of all windows in console application?[^]
 
Share this answer
 
v2
Comments
Stan Huang 3-Feb-15 3:08am    
It seems not working. MessageBoxW() is C++, not C#.
I think the problem is that the caller is a timer event handler,which is at background thread.
Refer here:TopMost MessageBox[^]
It works; but I still wonder the simpler solotion. In my opinion, showing message at top of all windows or at least the current window must be very popular option in Windows programming. How come it needs so lots of codes to do it? It should need only one parameter or one or two statement to set it.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900