CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Multiple Forms

  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Multiple Forms

    Hi All

    I have two forms that are shown at the same time when my application starts. I have a timer on both forms. Form A has a timer that runs every 20 seconds

    Form B has a timer that runs every 100ms.

    When Form A timer runs its pauses the timer in Form B until the timer has finished doing its job.

    How do I get these timers to run idependantly so that neither of the timers effect each other??

    Regards

    Djbell

  2. #2
    Join Date
    Jun 2007
    Posts
    16

    Re: Multiple Forms

    Make a third timer to delegate them.

    - Joe

  3. #3
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Multiple Forms

    Both forms are executing on the UI thread. The Tick events will be being raised at the correct times, +/- the 55 millisecond accuracy of the Windows.Forms.Timer class. That said, no thread can do two things at once so only one Tick event can be handled at a time. The other event will be queued until the thread is available to process it.

    The answer is to process the events on different threads. Instead of using a Windows.Forms.Timer use a Timers.Timer on at least one of the forms. If the SynchronizingObject is set to Nothing the Elapsed event will be raised in a background thread and not interfere directly with the other.

    Note that you will have to use delegation to access any controls but that's not hard when you know how. If you need to access controls from both Timers' event handlers then I'd suggest using a Timers.Timer on both forms.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured