Skip to Content
author's profile photo Former Member
Former Member

Single Thread

Hello Forum,

I'm trying to put a webbrowser control on a form and I get this error message: System.Threading.ThreadStateException: The ActiveX-Control 8856f961-340a-11d0-a96b-00c04fd705a2 could not be instantiate, because the current Thread is no Single Apartment Thread.

I have a starter project and there is [STAThread] set for the main routine. Are SAP B1 Forms no single thread forms?

Thanks

Mark

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Mar 26, 2015 at 01:27 PM

    Hi Mark,

    Are you creating any other thread where this form is running? If so you have to make that thread STA:

    MyThread.ApartmentState = Threading.ApartmentState.STA


    Best regards,

    Pedro Magueija


    View Pedro Magueija's profile on LinkedIn

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 21, 2016 at 10:03 AM

    Hi Mark,

    Did you get this working.

    Had many problems using mixed Windows Forms and SBO Forms, but most problems are solved using this code:

    using System;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1 {
    
      static class Program {
    
      [STAThread]
      static void Main( ) {
      //Application.EnableVisualStyles( );
      //Application.SetCompatibleTextRenderingDefault(false);
      Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
      Application.ThreadException += Application_ThreadException;
      Application.Run(new ProgramContext( ));
      Environment.Exit(0);
      }
    
      private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) {
      // ultimate exception handler
      }
    
      }
    
      class ProgramContext : ApplicationContext {
    
      private static SAPbouiCOM.Application SboApp = null;
    
      public ProgramContext( ) : base( ) {
      this.ThreadExit += ProgramContext_ThreadExit;
      // connect to SAP
      SboApp.AppEvent += SboApp_AppEvent;
      }
    
      void ProgramContext_ThreadExit(object sender, EventArgs e) {
      // unload application
      SboApp.AppEvent -= SboApp_AppEvent;
      }
    
      private void SboApp_AppEvent(SAPbouiCOM.BoAppEventTypes EventType) {
      if (EventType == SAPbouiCOM.BoAppEventTypes.aet_ShutDown)
      Application.Exit( );
      else if (EventType == SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged)
      Application.Exit( );
      }
    
      }
    
    }
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.