CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    90

    WPF Threading issue with Win32 app

    We are trying to integrate existing WPF window on to Win32 container application. The win32 application can integrate and show only Winforms Usercontrols.
    Since we already have a running WPF window code, we used the element host and we used the content presenter of the window inside the element host to show

    as a winforms usercontrol.The WPF window code overrides the function protected virtual void OnInitialized(EventArgs e) and calls first base.OnInitialized and then

    the custom code. The issue is here is that you can run the below code for the first instance from win32 container , but second instance when we execute same

    code , it throws the error "The calling thread cannot access this object because a different thread owns it." from the line base.OnInitialized when initialization

    AutoUpdate window = new Autoupdate();
    Even if we use the below code under dispatcher it throws the same error after the firstime.

    ElementHost elementHost = new ElementHost();
    elementHost.Dock = DockStyle.None;
    elementHost.Width = 150;
    elementHost.Height = 50;

    AutoUpdate window = new Autoupdate();
    ContentPresenter pres = new ContentPresenter();
    pres.Content = window.Content;

    elementHost.Child = pres;
    this.Controls.Add(elementHost);

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WPF Threading issue with Win32 app

    Is the second instance started on a different thread?

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