Launching forms from timer reset function

Posted on 2010-01-01
Last Modified: 2013-12-17
Hello there,

My requirement is to let's say lanch a form each 10 seconds so I figured I would use a timer.  However, whenever a form is launched by the OnTimer function (which is called whenever the timer resets, it's like the loading of the form never completes and the program is in an unresponsive state.  Note that the code below is not my real world scenario, but I get the same behavior.

Any suggestions or alternatives?
public void start()


    System.Timers.Timer pollTimer = new System.Timers.Timer();

    pollTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer);

    pollTimer.Enabled = true;

    pollTimer.Interval = 10000;



public void OnTimer(Object source, System.Timers.ElapsedEventArgs e)


    Form1 frm = new Form1();



Open in new window

Question by:acicovic
    LVL 85

    Accepted Solution

    The System.Timers.Timer runs in its own thread which is probably the root of your problem.

    (1) Switch to System.Window.Forms.Timer (the one in the control toolbox by default)
    (2) Use a Delegate and Invoke() from your Elapsed() event to move to the main UI where it is safe to create a form and display it.
    LVL 13

    Expert Comment

    Alos: pollTimer  is destroyed as soon as it leaves the start function as the timer is local to the function only. Also try move the Timer object out of the function and onto the form/ class as a member variable.
    LVL 2

    Author Comment

    For anyone having the same problem, I changed the timer to a System.Windows.Forms timer and everything worked.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now