0

I have a WPF class file (.DLL) which opens a webbrowsercontrol and returns some value.

I have used this as a reference in an ASP.NET website ... but i get the below error when the code hits the webbrowsercontrol.

The calling thread must be STA, because many UI components require this.

I looked all over, but i cannot seem to use [STAThread] or Dispatcher. Could someone please help me get around this ? here is the code.

WPFClass is the DLL file referenced.

using WPFClass;
using System.Threading;


public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        WPFClass.Browser Nav = new WPFClass.Browser();
        string response = Nav.Open();

        TextBox1.Text = response;

    }
}
Telson Alva
  • 842
  • 6
  • 22
  • 37
  • Refer to this question: http://stackoverflow.com/questions/2422709/is-it-ok-to-use-wpf-assemblies-in-a-web-app – Nate222 Jul 08 '15 at 10:22
  • Note that the answer in the duplicate question contains a reference to yet another answer, where you will find an actual implementation of an "STA thread pool" you can use to actually execute your STA-dependent code. IMHO, it's not the best implementation possible, but it is reasonably simple and should work for you. – Peter Duniho Jul 08 '15 at 17:07

0 Answers0