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

  • Home
  • SEARCH
  • 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 3949914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:32:59+00:00 2026-05-20T01:32:59+00:00

This is an is this possible, and if so can you give me a

  • 0

This is an “is this possible, and if so can you give me a quick example because I can’t find one online?” kind of question.

I have a number of completely separate (i.e. “embarrassingly parallel”) processes that I want to run in parallel using the Task Parallel library in .NET Framework 4 using C#. Some of these processes require the use of software that can be accessed via COM/OLE automation.

Specifically, there is a Parallel.Foreach() loop that divides up the tasks from a list of items, basically calling a different function inside the Parallel.Foreach to handle the processing (so some of these functions employ COM libraries to work).

Is this possible? Thanks.

  • 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-20T01:33:00+00:00Added an answer on May 20, 2026 at 1:33 am

    It’s 100% possible to use COM objects with the TPL. While it’s true that, by default, the TPL will use the standard .NET ThreadPool, the TPL has an extension point via the TaskScheduler class which enables you to provide your own scheduler which can dispatch work to threads which you’ve created.

    In the case of of using COM objects you first need to know if the COM class requires STA threading or MTA threading. If MTA threading, then there’s nothing special that needs to be done because the COM class can already be used from any random thread. Unfortunately most classic COM objects tend to rely on STA threading and that’s when you’d need to employ a custom TaskScheduler so that whatever .NET thread you’re using them from has been initialized as an STA compatible thread.

    While TaskSchedulers are not exactly trivial to write, they’re not really that hard to write either if you’ve got a basic understanding of threading. Luckily the ParallelExtensions Extras library already provides an StaTaskScheduler class so you don’t even need to write anything yourself. There’s a great blog post here by the PFX team that discusses the implementation of and some use cases for the the StaTaskScheduler class.

    Basically though, you’ll want to initialize a new StaTaskScheduler as a static somewhere on one of your classes and then just start your Tasks specifying that they are scheduled by that instance. That would look something like this:

    // Create a static instance of the scheduler specifying some max number of threads
    private static readonly StaTaskScheduler MyStaTaskScheduler = new StaTaskScheduler(4);
    
    ....
    
    // Then specify the scheduler when starting tasks that need STA threading
    Task.TaskFactory.StartNew(
    () =>
    {
        MyComObject myComObject = new MyComObject();
    
        myComObject.DoSomething();
    
        // ... etc ...
    },
    CancellationToken.None,
    TaskCreationOptions.None,
    MyStaTaskScheduler);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible? In an events system an event can have multiple times. (ie,
If this is possible, one can index into a variadic template parameter pack without
Does anyone know if this is possible? I can't see to find much info
I have seen this question and a number of blog posts related to using
Let me give you a quick example of my problem. I can't seem to
Is this possible? My code works on Firefox. I can also get webkit to
I am trying to alter svg image colors with javascript. Is this possible? Can
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
I know this is possible in Perl, but I was wondering if this can

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.