Todd
Todd

Reputation: 139

Delegate launched with .BeginInvoke keeps throwing ThreadAbortExceptions?

Good morning

I have a block of code that is being run from a WCF service method. The intent is to execute an asynchronous process which will allow the original WCF service method to return a result without waiting for the process to run.

    public delegate void DoItAsync();
    public static void TriggerDocSubmissions()
    {
        var docSubmissionClient = new Services.DocumentSubmitter();
        try
        {
            var myAction = new DoItAsync(docSubmissionClient.DoWork);
            myAction.BeginInvoke(null, null);
        }
        catch (Exception ex)
        {
            LogManager.LogException(ex);
        }
    }

The code within the DoWork method shown above keeps throwing ThreadAbortExceptions. I understand that the thread being summoned to execute 'DoWork' to is a pooled thread, and that if anything aborts that thread then it will be perceived as a ThreadAbortException from the process running on that thread.

I do not need to know the result of the execution of the DoWork method because it updates the database with it's outcome.

In some cases, I'm seeing ThreadAbortExceptions very quickly after beginning execution of DoWork (milliseconds), sometimes it takes a longer time (20-30) seconds, sometimes it works without any issue?

How can I affect/better understand the ThreadAbortExceptions and their origin? Why does it happen sometimes and not other times?

I've looked up more information about the BeginInvoke pattern, and can't find any information about how to manage/influence ThreadAbortExceptions.

Any insight would be appreciated.

Upvotes: 0

Views: 57

Answers (0)

Related Questions