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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:31:09+00:00 2026-05-22T22:31:09+00:00

So I invoke a thread from managed code this way: Action<EFScmTechnologiesContext, long, long> updateReference

  • 0

So I invoke a thread from managed code this way:

 Action<EFScmTechnologiesContext, long, long> updateReference = UpdateReferenceBaseline;
 IAsyncResult ar = updateReference.BeginInvoke(_context, baseline.Id, updatedBaseline.Id, null, null);

I have taken care to make sure that this class’s destructor waits for the thread to complete. So for most normal cases, the thread is allowed to do its work before the process exists. However, I suspect there might be conditions (unhandled exceptions on other thread perhaps?) where the destructor is not called and the thread is terminated without being allowed it to complete.

What do I have to do . . . either in the delegate or the wrapper class, to make sure this thread is allowed to complete regardless of exceptions, aborts or exits in another thread?

I read about UnhandledExceptionHandler(), but wasn’t sure exactly what to do with it . . . I think by the time that handler is called my thread is already toast. I could also put a try/catch block in the delegate, but that would mean the thread is already interrupted from doing its current operations.

I also recognize that depending on the exception involved, the whole application environment might be toast . . . so even if I can catch/prevent the thread’s termination . . . I probably should only allow it 30 seconds or so to try and complete its work and then let it die regardless . . .

I see lots of information on threads and exceptions in general, etc . . . but very little on the Exit process and the final moments of a process’s life . . . if anyone has a pointer to a good description, please . . .

  • 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-22T22:31:10+00:00Added an answer on May 22, 2026 at 10:31 pm

    I think your way of doing this should be safe, unless your finalizer (also known as destructor) throws an exception itself.

    But I would not recommend to you doing it this way. A better way would be to create a new thread for your method. Unless you change the Thread.ISBackground property, it is not created as a background thread, which means that the whole program will continue on running, until this thread stops:

    var thread = new Thread(() => UpdateReferenceBaseline(_context, baseline.Id, updatedBaseline.Id, null, null));
    thread.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PostSharp 2.0 includes a CLR host and implements IHostAssemblyStore::ProvideAssembly. From managed code, I invoke:
I have a deadlock when I invoke the UI thread from a worker thread.
I have this simple code: public void Run() { var invokerThread = new Thread(new
I want to do something like this in C# (more specifically, WPF): Thread.Invoke(MyCallback, 1000);
I am running this code in a seperate thread on my C# Winforms app
Based on all my reading there should be one GC thread to invoke all
How do I invoke a console application from my .NET application and capture all
In Linux When I invoke python from the shell it replicates its environment, and
How do you invoke a tkinter event from a separate object? I'm looking for
I need to invoke a VBA macro within an Excel workbook from a python

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.