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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:35:40+00:00 2026-05-25T00:35:40+00:00

i have main thread (MainThread) on which I create new thred (lets call it

  • 0

i have main thread (MainThread) on which I create new thred (lets call it NewThread). In NewThread I call a method that want to invoke some method for MainThread.

The problem is that when I call NewThread.Join() from MainThread, Invoke method from NewThread cant be accomplished/terminate (and whole application freeze for ever…) because MainThread is waiting for NewThread to terminate…

sth like vicious circle… Any ideas how to solve it? I need to have possibility to terminate/abort NewThread from MainThread and be shure NewThread no longer exist.

I hope I was specific enough.

Main thread:

void method()
    {
        if(currentthread!=null)
        {
            currentthread.Join();
            currentthread=null;
        }

        sth...

        Backgroundworker worker = new Backgroundworker();
        worker.DoWork += delegate (...)
            {
                currentthread=Thread.CurrentThread;
                Func();
            }
            ....
}

NewThread:

delegate void FuncDel();
void Func()
{

    if(MainThread.InvokeRequired)
{
    FuncDel funcD = new FuncDel();
    MainThread.InvokeRequired(funcD);
          return;
} 
 ....
}
  • 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-25T00:35:40+00:00Added an answer on May 25, 2026 at 12:35 am

    Well, the obvious answer is that your main thread should never Join() your worker thread if there’s a chance the worker thread is going to try to Invoke() something on the main thread.

    If you are only using Join() to wait for a shutdown on the main thread, you should first do something like a Thread.Abort(), or better yet, use a thread synchronization object like a Mutex or a shared variable, to indicate to the worker thread that it needs to abort. Once you have signaled the worker thread to abort, then allow your main thread to Join() it; your worker thread should always check to see if it has been aborted before trying to Invoke a method on the main thread.

    If you’re using Join() for some other reason, you should again look into the thread synchronization objects like a Mutex. These allow your threads to wait for each other to send them signals — your worker thread could “wake up” your main thread before it needs to Invoke(), to ensure your main thread is getting CPU time to do it’s work.

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

Sidebar

Related Questions

I have the main thread from which I start a window using invokeLater .
I have a main thread that invokes a child thread function at different times
I have a windows form on the main thread and another thread that does
I have an application that has two threads. The first one (the main thread)
I have a program that runs in a few threads. The main thread shares
I'm writing an Android app. I have a main method, which creates and runs
I have a method that contains an asynchronous call like this: public void MyMethod()
i have a listoddata and a list of thread in main thread .i am
I have my main GUI thread, and a second thread running inside it's own
My Goal I would like to have a main processing thread (non GUI), and

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.