troubleshooting Question

Errors which occur in worker thread not being raised in main application thread? (Using VB.Net)

Avatar of krtarwood
krtarwood asked on
ASP.NET
14 Comments2 Solutions316 ViewsLast Modified:
Hello Experts!

I am sort of new to threading in ASP.Net so hopefully you can shed some light on what I am doing wrong here.

Essentially I have an application that runs a pretty lengthy process in a seperate sub. I want to thread the sub so I simply changed the call to the long running sub from Call buildDoc() to:

        Dim NewThread As New Thread(New ThreadStart(AddressOf buildDoc))

        NewThread.Priority = ThreadPriority.Lowest
        NewThread.Name = "CatalogBuild"
        NewThread.Start()

Seems like a good idea in theory as it does free up my UI to do other things, however it is obvious that the buildDoc subroutine is failing somewhere along the line (It programmatically instantiates a connection to a VPN and performs some transactions with our AS/400). The sub worked fine with the simple call but began failing after I threaded it. The problem is the process seems to die without throwing any of the exceptions that it used to so I can't tell what is going wrong.

I was told elsewhere that the only way to return exceptions thrown by threaded processes was to use delegates but I am unsure how that would help. Ideas? I have a top-level error handler setup in global.asax as such:

        Private Sub Global_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
            Application("_ERROR") = Server.GetLastError()
            Dim ex As Exception = Server.GetLastError()

            If (Not ex Is Nothing) Then
                Dim innerException As Exception = ex
                ' Change to locale of error page
                Response.Redirect("~/error.aspx")
            End If

            ' Get rid of the progressbar on error
            Application("progress_" & Session.SessionID) = 100
            Application("complete_" & Session.SessionID) = True
        End Sub

Perhaps the above handler is not taking into account the specific type of exception that threads produce and hence isn't tripping when the error occurs?

I will post the contents of the buildDoc() sub if need-be but it is quite lengthy. You can view what it looks like by checking out the last comment on this previous post: https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21933943.html

Any help would be thoroughly appeciated!

Thanks,
K
ASKER CERTIFIED SOLUTION
existenz2

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros