<div dir="ltr">I have separate AppDomains (not primary) where I use RabbitMq.Client (RMQC). When I try to unload domain it seems like RMQC prevents to do it gracefully.<div>ConnectionBase creates 2 _foreground_ threads which in case of absence of messages are blocked inside Socket.Receive and do not check external flags like m_running/m_closed.</div><div>Yes, ConnectionBase has subscription to DomainUnload:</div><div><br></div><div><pre><a title="System.AppDomain
CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.AppDomain">AppDomain</a>.<a title="AppDomain System.AppDomain.CurrentDomain { ... }
CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.AppDomain/property:CurrentDomain:System.AppDomain">CurrentDomain</a>.<a title="event EventHandler System.AppDomain.DomainUnload;
CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.AppDomain/event:DomainUnload:System.EventHandler">DomainUnload</a> += <font color="#1000a0">new</font> <a title="System.EventHandler
CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.EventHandler">EventHandler</a>(<font color="#1000a0">this</font>.<a title="void RabbitMQ.Client.Impl.ConnectionBase.HandleDomainUnload(object sender, EventArgs ea);
CTRL+Click to open in new tab." href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://RabbitMQ.Client:3.2.1.0:89e7d7c5feba84ce/RabbitMQ.Client.Impl.ConnectionBase/HandleDomainUnload(Object,System.EventArgs)">HandleDomainUnload</a>);
</pre><pre><br></pre><pre><span style="font-family: Arial, Helvetica, sans-serif; white-space: normal;">but it won't be called if any foreground threads prevent domain from unloading.</span><br></pre><pre><span style="font-family: Arial, Helvetica, sans-serif; white-space: normal;">It would be nice if all threads created inside ConnectionBase would have IsBackground set to true.</span></pre></div></div>