Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:33:48+00:00 2026-05-21T07:33:48+00:00

I am implementing an interface that has a BeginSomething() and EndSomething() pair, and my

  • 0

I am implementing an interface that has a BeginSomething() and EndSomething() pair, and my implementation is in a method Execute()

So I create an Action action = Execute, and call action.BeginInvoke in BeginSomething, and action.EndInvoke in EndSomething. However my Execute method has to be called by a thread whose apartment state is STA (single-threaded apartment). Usually this is done by calling Thread.SetApartmentState, but in this case I don’t know which thread is going to invoke my method.

How should I make the calling thread STA?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:33:49+00:00Added an answer on May 21, 2026 at 7:33 am

    If your class is implementing those Begin/End pair methods as per an interface, then you have control over how the work is actually done. Delegates (of which Action is a typed generic of) will use the default thread pool I believe, and so will be performed by a shared re-usable available thread. Since messing with the thread pool isn’t feasible, straight delegates are a no-go in this case.

    You’ll have to create your own Thread object (passing in a new ThreadStart to your method) and set it’s apartment state as you’ve already indicated. That method is simply going to have to have its own way to callback, since vanilla Threads don’t provide a convenient way to my knowledge.

    You could also optionally use Tasks along with a custom StaTaskScheduler if you’re using .NET 4.0, but this could be more trouble and/or complication than it’s worth since it adds a lot of dependencies. It does eliminate the callback problem, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing the IProcessFactory interface that has the following method: IProcess newProcess(ILaunch launch,
I'm implementing an interface that has functionality similar to a table that can contain
When implementing an interface in eclipse, it has a really nice feature that lets
I am implementing a protocol that has a method called fbDidExtendToken:. For some reason,
I'm working with java. I have an interface that has an annotated method in
In .NET, if I'm implementing an interface that contains an event, but that event
I have an interface and two objects implementing that interface, massively simplied; public interface
I'm trying to grasp higher-order-polymophism in scala by implementing a very basic interface that
I've heard that implementing an interface of constants is an anti-pattern 'cause such interfaces
I have noticed that doing actions like implementing an interface, that a small rectangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.