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. C#
  4. STA model and new thread

STA model and new thread

Scheduled Pinned Locked Moved C#
csharpc++comquestion
2 Posts 2 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.
  • M Offline
    M Offline
    myshketer
    wrote on last edited by
    #1

    Hello! I want to know how .NET managed threads in STA model application. When I create new thread should I init COM library in some way (like CoInitialize() in C++) or .NET did it for me? Best regards, M.

    J 1 Reply Last reply
    0
    • M myshketer

      Hello! I want to know how .NET managed threads in STA model application. When I create new thread should I init COM library in some way (like CoInitialize() in C++) or .NET did it for me? Best regards, M.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      .NET does it all for you; you don't need to call CoInitialize. Note that if you're using a COM object on a background thread, ensure that the thread is STA. You can do this by calling thread.SetApartmentState before the thread has started executing. Note that the UI thread for Windows Forms (and WPF, I believe) applications are STA by default, so if you created a COM object on that thread, you'll be fine.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Just F-ing Do It :) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      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