Click here to Skip to main content
14,270,104 members
Rate this:
Please Sign up or sign in to vote.
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?

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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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?[^]
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100