Results 1 to 16 of 16

Thread: Can't we simultaneously instantiate multiple forms?

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Arrow Can't we simultaneously instantiate multiple forms?

    I used different backgroundworkers to instantiate some 'heavy' forms thinking that it will reduce the time to instantiate them if I did them at once but it looks like I am wrong since it is still taking about 43 seconds to load all of them. Am I missing something or do you have a tip on how I can speed up their instantiation?

    TIA
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can't we simultaneously instantiate multiple forms?

    You can't really create forms using a BackgroundWorker anyway because then each form is owned by a different thread. Any communication between them would require invocation of a delegate.

    As for the speed, it might depend on how many tasks are actually being performed concurrently and how many are interleaved. Sometimes multi-threading can actually make things take longer because of the overhead of context switching.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    The forms are MDIChilds and yes I am using delegates to set the MDIParent. I am doing the instantiation upong logging-in and while the Splash form is shown. The code is just as simple as

    Code:
    Form1 frm = new Form1()
    frm.MDIParent = this
    I thought there should be a way to intantiate them all at once, is that not possible?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can't we simultaneously instantiate multiple forms?

    No it's no possible. Think about it. Obviously an MDI parent form would have to be able to access its MDI children. Accessing a control from any thread other than the one that created it is illegal though, so how could the parent possibly access the children if they were all created on different threads?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    Actually it is working, I am getting the forms by this.MdiChildren and it is listed there. Using a delegate for the "MDIParent = this" works, I am wondering why you are thinking that it is not possible? Am I missing something?

    My only concern is to speed things up.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can't we simultaneously instantiate multiple forms?

    Can you show the code you're using? I think you'll find that you are not actually doing what you think you're doing. That's possibly why you didn't see any time difference.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    It looks like this. Is this what you are looking for or the code for the backgroundworker? I am just calling this procedure from the DoWork procedure of the backgroundworker.


    Code:
    Private Sub InstantiateForm()
        If Me.InvokeRequired Then
            Dim d As New InstantiateFormCallback(InstantiateForm)
            Me.Invoke(d, Nothing)
        Else
            Dim frm As Form1 = New Form()
            frm.MdiParent = Me
        End If
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Can't we simultaneously instantiate multiple forms?

    When you call Me.Invoke follow it through and look at the callstack, you should see that the thread you are on is actually the main thread, it will just block your current thread until the main thread is avail, then use the main thread, which in turn blocks all the other threads and hands back the calling thread when it is finished.

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Can't we simultaneously instantiate multiple forms?

    To add, you can suspend the layout of forms during heavy load to stop screen-redraws/resizing. Lookup Suspendlayout/resumelayout. There is also an API to lock a window which I have had to use in the past to remove drawing while resizing mdi forms in a complex tab interface.

  10. #10

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    So you mean to say what I want is not possible?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Can't we simultaneously instantiate multiple forms?

    Errrr...correct. The only way I can think of is to use multiple processes and then use api's to drag windows across, but it would be really really really bad . I would work on speeding up your loading times.

  12. #12

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    Quote Originally Posted by Grimfort View Post
    To add, you can suspend the layout of forms during heavy load to stop screen-redraws/resizing. Lookup Suspendlayout/resumelayout. There is also an API to lock a window which I have had to use in the past to remove drawing while resizing mdi forms in a complex tab interface.
    Will try Suspendlayout/Resumelayout if it will provide some improvement.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    After profiling the controls I observe that this one 3rd party control (numericbox) tends to slow the loading of the forms and the usercontrols. I replaced them with plain textboxes and the speed improved significantly. From more than 45+ seconds it is now playing between 13-18 seconds to instantiate those forms. It is much faster now and I can alreeady lazy load the usercontrols which is not immediately needed.

    I will keep this thread open since my original question was not answered satisfactorily or that it is ill advised to do so. If anyone have some recommendations for speeding things up then they are still very much welcome to share.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  14. #14
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Can't we simultaneously instantiate multiple forms?

    Do you need to load all the forms on startup? Can't you load as and when required, or at least load them up without data?

  15. #15

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can't we simultaneously instantiate multiple forms?

    They are only instantiated and hidden. The Load event is not fired hence they don't look loaded to me. =)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  16. #16
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Can't we simultaneously instantiate multiple forms?

    I'll rephrase, do you need to create instances of all these forms? Or are you just trying to save the user waiting while moving around your app?

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