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 769755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:23:15+00:00 2026-05-14T18:23:15+00:00

So far I have this code run when the X button is clicked, but

  • 0

So far I have this code run when the X button is clicked, but I’m not sure if this is the correct way to terminate threads on a form on exit.

           Type t = this.GetType();
           foreach (PropertyInfo pi in t.GetProperties())
           {
                if (pi.GetType() == typeof(Thread))
                {
                    MethodInfo mi = pi.GetType().GetMethod("Abort");
                    mi.Invoke(null, new object[] {});
                }   
            }

I keep getting this error: “An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss.”

  • 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-14T18:23:16+00:00Added an answer on May 14, 2026 at 6:23 pm

    Clearly it is not the right way to abort that particular thread, the exception tells you so. The message shows that you are using a COM object on that thread. Maybe something like Microsoft Excel? Running COM objects on a worker thread is troublesome, they very commonly have strict threading requirements. One of which is that they are not thread-safe and have “apartment threading” affinity. An expensive word for “all your method calls on the object will run on the UI thread anyway”. Which makes it slower, defeating the advantages of threading completely.

    Anyhoo, don’t use Reflection to find your threads back, use the Thread field in your class directly. And make sure you shut down the thread in a controlled way rather than pulling the rug. This thread shows an example.

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

Sidebar

Related Questions

I have this code so far which perfectly but relies on there being a
This is what I have as far as code, it is in the first
I have this so far but the Column 'name' is ambiguous, so I want
I have this so far but I don't know how to write over the
So far i have this: mov ah,02h mov cl,11001100001111011101000b ;6,692,584 in dec mov dl,0
Thanks to everyone out there helping newbies like me. So far I have this:
I have this so far: http://jsfiddle.net/u5vhS/54/ . What I want to be able to
I have this trigger which works functionally (as far as I can tell by
I'm using the javascript module pattern, and have this so far: var APP; if(APP
I have used this effect before, everything is in order (As far as I

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.