Re: Relationship between Application.Exit() and AppDomain
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Thu, 24 Apr 2008 10:42:39 -0500
Sunny S wrote:
Hi Ben,
1. The Threads property of a Process instance should give you the set
of threads that are running in a given process or you can just use
Process.GetCurrentProcess.Threads.
2. Then for each thread in the ProcessThreadCollection returned by the
Threads property in (1) you can use the GetDomainID property to find
which AppDomains currently contain running threads and to map those
threads to individual AppDomains.
3. I am not sure if my speculations about your 3rd question are
correct, but I think that given the fact that AppDomains could be
unloaded and then recreated, even reused, I suspect, which is
certainly true for threads provided by the ThreadPool, associating an
AppDomain that started a particular thread with this thread or, the
other way round, associating a thread with an AppDomain that started
this thread might lead to confusion and/or could be costly. I doubt
that the runtime supports this. The only valid information would be
provided by an instant snapshot of which threads are running in which
AppDomains (see 2 above).
I was just trying to highlight the possibility that just because a thread is
currently running code in one AppDomain, doesn't mean it doesn't have other
AppDomains on the call stack and aborting the thread will interfere with
those other AppDomains. Or are cross-AppDomain calls always marshalled to a
thread dedicated to that AppDomain?
Consider for example the case where the plugin subscribed to an event in the
main program. When the main program fires the event handlers, the plugin
handler runs and hangs. How do you unload the AppDomain without throwing a
ThreadAbort exception up through the main program method which raised the
event?
Regards,
Sunny
"Ben Voigt [C++ MVP]" wrote:
"Jeffrey Tan[MSFT]" wrote:
Hi Willy,
Thank you for pointing out the document.
Yes, it seems that these issues are documented in MSDN clearly.
CannotUnloadAppDomainException is expected to throw in some
scenarios. Catching CannotUnloadAppDomainException and calling
AppDomain.Unload again should be the solution. Also, I think we'd
better give a guard to this. For example, we should check if this
will result in an infinite catch...re-calling loop. If so, I think
we have to kill the threads in the target AppDomain to recover from
this situation. Yes, this may not be an elegant solution, but we
have to defense this situation.
Is there any supported way to enumerate all Threads? All Threads
running code from a particular AppDomain? All Threads started by a
particular AppDomain? Nevermind the problems with threads ignoring
abort because they are in an I/O call or other native code.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the support we
provide to you. Please feel free to let my manager know what you
think of the level of service provided. You can send feedback
directly to my manager at: msdnmg@xxxxxxxxxxxxxx
This posting is provided "AS IS" with no warranties, and confers no
rights.
.
- Follow-Ups:
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- References:
- Re: Relationship between Application.Exit() and AppDomain
- From: Jon Skeet [C# MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Jeffrey Tan[MSFT]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: "Jeffrey Tan[MSFT]"
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- From: "Jeffrey Tan[MSFT]"
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: "Jeffrey Tan[MSFT]"
- Re: Relationship between Application.Exit() and AppDomain
- From: Willy Denoyette [MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: "Jeffrey Tan[MSFT]"
- Re: Relationship between Application.Exit() and AppDomain
- From: Ben Voigt [C++ MVP]
- Re: Relationship between Application.Exit() and AppDomain
- From: Sunny S
- Re: Relationship between Application.Exit() and AppDomain
- Prev by Date: Re: A question about life cycle of an object.
- Next by Date: Re: Relationship between Application.Exit() and AppDomain
- Previous by thread: Re: Relationship between Application.Exit() and AppDomain
- Next by thread: Re: Relationship between Application.Exit() and AppDomain
- Index(es):
Relevant Pages
|