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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:08:41+00:00 2026-06-11T08:08:41+00:00

Is there any way i can create a thread which ends no matter what

  • 0

Is there any way i can create a thread which ends no matter what after 1 min?

Currently i make a thread to login to a website code is below:

 private void runBrowserThread()
    {

        specialCheck = 0;
        var th = new Thread(() =>
        {
            var br = new WebBrowser();
            browserCounter = 0;
            br.ScriptErrorsSuppressed = true;
            br.DocumentCompleted += browser_DocumentCompleted;
            br.Navigate("https://www.xample.com/login");
            Application.Run();

        });

        th.SetApartmentState(ApartmentState.STA);
        th.Start();
        th.Join();
    }

BUT there are a lot of complications in the process so i do not want to code them all , what i am thinking something like a self destruct i can use when making this timer ,so that no matter what if a code is stuck , it does not reach one of the Application.Exitthread() it will be stuck there forever so a self destruct after 1 min , Exits the threads so the code can move on.

Because currently i have Application.Exitthread() at many places but i sometimes the code is stuck does not reach any, so let me know if there is any way.

  • 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-06-11T08:08:43+00:00Added an answer on June 11, 2026 at 8:08 am

    As you’re already blocking on th.Join you could use that to terminate the thread, like so:

    Boolean success = th.Join( 60 * 1000 ); // 60 second timeout
    if( !success ) th.Abort();
    

    If you don’t want to block on Join, then you could spawn a second watchdog thread that exists only to block on Join and perform the timeout and termination task instead of the instigator thread.

    Also, use of Application.ExitThread isn’t good design. Threads can terminate by returning from their entrypoint method – it also removes an unnecessary dependence on the Application class and its associated System.Windows.Forms assembly.

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

Sidebar

Related Questions

I wish to know is there any way that I can create the threads
Is there any way I can create a UAC-like environment in Python? I want
Is there any way that I can create a new delegate type based on
Is there any way that I can use JavaScript (and jQuery) to create a
We can't use java.text.SimpleDateFormat, so is there any way to create date object from
Is there any way can declare a bean in just like JSP UseBean in
Is there any way I can set a formatter on models that will convert
Is there any way we can fetch X509 Public Cetrificates using c# from AD
Is there any way I can use JPA or hibernate annotations to specify the
Is there anyway I can create nodes out of a string? I've searched the

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.