PC Review


Reply
Thread Tools Rate Thread

AppDomain.Unload() hangs

 
 
John Price
Guest
Posts: n/a
 
      22nd Nov 2005
I'm writing a Windows Service that loads and manages a number of
"sub-services". Each sub-service implements a simple interface
(start(), stop()) and gets loaded into its own AppDomain. There is
also a client interface that allows an administrator to connect to the
service using remoting and start and stop sub-services without having
to restart the whole thing. All of this is with v1.1 of the framework.

When a sub-service is shutdown, I do a call to AppDomain.Unload() to
clear everything out and get a fresh start. Unfortunately,
AppDomain.Unload() seems to be finnicky and depending on how I do what
would seem to be entirely unrelated things, it can consistently hang.
I've seen other people reporting similar problems in newsgroups, but I
haven't seen anything that seems to explain what I'm seeing.

I was at first just having problems with the service itself. When I
tried to unload the appdomains on server shutdown in the main
application thread, AppDomain.Unload() would completely hang. Through
some experimentation, I discovered that if I instead performed the same
operations in a new thread, calls to AppDomain.Unload() return no
problem and everything works fine. So now I've got a pretty useless
extra thread, but it works.

Now I'm having an issue with the client. When I initialize remoting
programmatically in the server, connect with my client, and instruct
the server to shut down a particular sub-service, things work fine. If
instead I initialize remoting through a configuration file,
AppDomain.Unload() hangs when the client tries to stop the sub-service.
As far as I can tell, my two remoting configurations should be the
same:

BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

BinaryClientFormatterSinkProvider clientProv = new
BinaryClientFormatterSinkProvider();

IDictionary props = new Hashtable();
props["port"] = 1234;

TcpChannel chan = new TcpChannel( props, clientProv, serverProv );

ChannelServices.RegisterChannel( chan );
RemotingConfiguration.RegisterWellKnownServiceType(
typeof( MyType ),
"MyUri",
WellKnownObjectMode.Singleton );

Versus:

<system.runtime.remoting>
<application name="MyApplication">
<channels>
<channel ref="tcp" port="1234">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>
</channels>
<service>
<wellknown mode="Singleton"
type="MyType, MyAssembly"
objectUri="MyUri"/>
</service>
</application>
</system.runtime.remoting>

At this point, I have absolutely no clue what causes AppDomain.Unload()
to hang, since the two fixes I've found seem entirely unrelated. I've
also tried simplifying the entire thing to the point that I could post
my code, but the problem only seems to arise once both my service
manager and my individual sub-services reach a certain level of
complexity. For trivial services, or a trivial service manager,
AppDomain.Unload() always seems to work.

Does anyone have any idea what might be causing AppDomain.Unload() to
not return? I'm not too desparate at the moment since I've got work
arounds for the cases I've run into, but it's a little scary to wonder
if every seemingly unrelated change I make could reintroduce the
problem.

John.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
appdomain.unload sam.m.gardiner Microsoft Dot NET Framework 3 9th Aug 2007 01:48 PM
appDomain Unload =?Utf-8?B?UmFpbg==?= Microsoft C# .NET 1 30th Jan 2006 08:04 AM
AppDomain / Object Lifetime & AppDomain.Unload =?Utf-8?B?QXJ0aHVyIE0u?= Microsoft Dot NET Framework 1 12th Jul 2005 08:09 PM
AppDomain.Unload John Wood Microsoft C# .NET 4 12th Oct 2004 12:36 AM
unload assembly - AppDomain.Unload does not work as expected =?Utf-8?B?RGllcmsgRHJvdGg=?= Microsoft Dot NET Framework 2 4th Apr 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:48 PM.