Results 1 to 3 of 3

Thread: Load Control in the background

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833

    Load Control in the background

    i have a 3rd party control... its a complex mess of 15 required DLLs, but i am able to load it at runtime and assign to to a panel

    it takes about 10 seconds to load, during that time my applicaiton hangs.

    i would really like to load it in the background, i tried a background thread but it generates a runtime error and says it needs to be in the UI thread

    anyway around this?

    wish i knew more about the control itself, it was build in WPF

    here is the code i use to load it, it fails on client = New FullMapsClient




    Dim ap = New System.Windows.Application()




    ctrlHost = New ElementHost()
    ctrlHost.Dock = DockStyle.Fill


    client = New FullMapsClient

    client.InitializeComponent()

    ClientPanel.Controls.Add(ctrlHost)

    ctrlHost.Child = client
    ctrlHost.Focus()
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Load Control in the background

    There isn't a good way around this. Any UI control has to be on the UI thread. If you created it in a background thread, it may never end up with UI thread affinity, and therefore not be able to handle or initiate events. That would pretty thoroughly suck, as the control might be there, but it would act in really weird ways, if it acted at all.

    There are a couple things you can think about:

    1) If the issue is showing the control, you are hosed. However, if the issue is displaying data in the control, then that's a different story. I have a program that shows some queries built around data that is really painful to put together. Those controls can take 10 seconds to populate, but that is because of the views, not because of the controls. Therefore, I launch a thread when the program starts that begins building the views. Once the views are ready, I load them to the controls (that has to happen using standard means to access UI controls from a background thread). Fortunately, the user won't get to the form for 10 seconds, so they never see the delay.

    2) You could shift the whole thing to startup by creating the control or form as the first act (unless it is the main form). This won't speed up a single thing, and will mean that your program shows a splash screen for the whole load time. That's not great, but we are all used to it, as VS itself can take that long to load.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833

    Re: Load Control in the background

    thanks, its a special component that wouldn't be used by every user, so i will just load it when they need it the first time. not a huge deal, but make me think there must be a way around it

    oh well!

    thanks
    Kurt Simons
    [I know I'm a hack but my clients don't!]

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