Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attempted to Access an Unloaded AppDomain

Status
Not open for further replies.

Meleagant

Programmer
Aug 31, 2001
166
US
All,

Does anyone know what could cause "Attempted to Access an Unloaded AppDomain" errors? I'm beginning to see these in the windows event log. Basically I have some long running executables which are started in new threads. But they seems to just die and looking into things I'm seeing these errors about the est time of death.

Here is the new thread code:
Code:
<WebMethod()> Public Function RunCostProcesses(ByVal DatabaseId As String, ByVal StartDate As Date, ByVal EndDate As Date) As String

    Dim clsTest As New RunProcesses(DatabaseId, StartDate2, EndDate2)
    Dim newThread As Thread = New Thread(New ParameterizedThreadStart(AddressOf RunCostProcesses))
    newThread.Start(clsTest)

    Return String.Empty
    
End Function

Private Sub RunCostProcesses(ByVal obj As Object)

    Dim clsTest As RunProcesses = CType(obj, RunProcesses)
    clsTest.Start()

End Sub

This thread calls an executable and has the potential to run for hours. For months things have been working but all of a sudden the process never completes and in the web servers event log I am starting to see Attempted to Access an Unloaded AppDomain errors.

Anyone have any experience with this type of error? Also these errors only seem to happen overnights. Processing during the day is not a problem.

Here is the call to the exe:
Code:
Private Sub RunPhase2()

    Dim psi As System.Diagnostics.ProcessStartInfo
    Dim processPath As String

    processPath = String.Format(Me.ProcessPath, "Phase2.exe")

    Dim arguments As New StringBuilder
    arguments.AppendFormat(" {0} {1} {2} ", Me.DbId, Me.StartDate2.ToString("MM/dd/yyyy"), Me.EndDate2.ToString("MM/dd/yyyy"))

    psi = New System.Diagnostics.ProcessStartInfo()
    psi.FileName = processPath
    psi.Arguments = arguments.ToString
    psi.UseShellExecute = False
    psi.CreateNoWindow = True
    psi.WorkingDirectory = Me.WorkingDir

    Dim proc As New System.Diagnostics.Process
    proc = System.Diagnostics.Process.Start(psi)
    proc.WaitForExit()
    proc.Close()

End Sub



* Sine scientia ars nihil est
* Respondeat superior
 
just guessing, but the application is stopping (or restarting) even though the back ground threads aren't finished. this is inherent with IIS and the web environment. if memory consumption become too high or no one is accessing the website then IIS will shut down that process. IIS isn't aware of the background work so it will shut down.

you need to track how many back ground threads are running and in Global.Application_End check the status of these background threads. either terminate the thread before it's finished, or wait for each thread to finish before shutting down.

I would use a service bus and push the background work to a windows service, completely independent of the website. the website just fires a message off along the service bus. the windows service picks up the message and does the work. mass transit, rhino.servicebus & nservicebus are all solid service bus platforms.


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top