Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. ActiveX and C#

ActiveX and C#

Scheduled Pinned Locked Moved COM
comcsharpasp-netquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FlamTaps
    wrote on last edited by
    #1

    Hello, I am trying to instantiate an ActiveX object. However, I am having some problems with threading. When I try to instantiate it without any threading statements, as follows: public static void Main(String[] args) { Application.Run(new SetupCreator()); } public SetupCreator() { ESRI.MapObjects2.Core.AxMap map1 = new ESRI.MapObjects2.Core.AxMap(); /*....*/ this.Controls.Add(map1); } I get the exception: "Could not instantiate ActiveX control '9bd6a64b-ce75-11d1-af04-204c4f4f5020' because the current thread is not in a single-threaded apartment." So, I did some research, and added the line [STAThread to just before main. With that there, I get "There is no source code available for the current location". I found another approach, which adds the line: Thread.CurrentThread.SetApartmentState(ApartmentState.STA); and getting rid of the STAThread line. Now, with this in place, I get "Failed to set the specified COM apartment state." So, I am a little lost as to what to do. Any suggestions?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups