ThreadStateException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cshen
    New Member
    • Mar 2007
    • 1

    #1

    ThreadStateException

    Hi All,
    I have a .net web service try to use an ActiveX control. The code got this error"
    "cannot be instantiated because the current thread is not in a single-threaded apartment"

    Someone suggested for the similar error for a windows forms program that to add
    [code=c]
    [STAThread]
    main()
    {
    }
    [/code]
    But my code is not windows form and does not have main().
    I have added [STAThread] over the method but still got this error.
    [code=c]
    namespace MyWebService
    {

    [WebService(Name space = "http://tempuri.org/")]
    [WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
    [ToolboxItem(fal se)]
    public class Service1 : System.Web.Serv ices.WebService
    {

    [STAThread]
    [WebMethod]
    public void MyMethod()
    {
    MyActiveControl ac = new MyActiveControl (); //causes error
    }
    }
    }
    [/code]
    Thanks for the help
    CS
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I had this same problem. Never found a solution. Not sure there is anything you can do. If you find out, let me know because I could use it too.

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      I found this while looking up this problem:

      MSDN Site About the Problem

      See if that helps

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by TRScheel
        I found this while looking up this problem:

        MSDN Site About the Problem

        See if that helps
        Hmm that looks good, except I was using a microsoft class (their webbrowser object) and I can't control it's internal threading.
        (It was related to printing)

        Comment

        Working...