Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to cause a thread to be created in another app domain?

Tags:

c#

.net

appdomain

Let's say I have a non default app domain. I want to get a reference to the Default app domain and cause a thread to be created within it, that runs a piece of code. Is this possible? The only way I can think of doing this is to re-load my assembly into the Default app domain and have some logic in one of the constructors of a type that figures out it's been reloaded for the purpose of launching this new thread. That seems rather convoluted. Is there a more direct way of doing this? On the other hand if there were a way of doing it, it would seem that would circumvent the entire security model of .NET.

like image 502
Leeks and Leaks Avatar asked Dec 07 '25 10:12

Leeks and Leaks


1 Answers

var ad = AppDomain.CreateDomain("mydomain");
ad.DoCallBack(() =>
  {
    var t = new System.Threading.Thread(() =>
    {
      Console.WriteLine();
      Console.WriteLine("app domain = " 
           + AppDomain.CurrentDomain.FriendlyName);
    });
    t.Start();

   });
like image 157
dan Avatar answered Dec 09 '25 22:12

dan