471,330 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

How to start a thread in a new AppDomain ?

Hi C# Experts:

I have 2 threads and I like to run them in seperate AppDomains.

In other words, I want to start 2 new AppDomains and then run a thread
within each of the AppDomains. How to do it?

Thanks
Polaris

Sep 6 '08 #1
1 6732
This bit of code should point you in the right direction.

public class Program
{
static void Main(string[] args)
{
AppDomain domain = AppDomain.CreateDomain("SecondDomain");
System.Threading.Thread.CurrentThread.Name = "Thread 2";

// Thread.Start in first domain
System.Threading.Thread thread = new
System.Threading.Thread(SomeMethod);
thread.Name = "Thread 1";
thread.Start();

// Current thread, for simpliicty, second domain
domain.DoCallBack(new CrossAppDomainDelegate(SomeMethod));

Console.ReadLine();
}

static void SomeMethod()
{
Console.WriteLine("Domain: " +
AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Thread: " +
System.Threading.Thread.CurrentThread.Name );

}
}

The CrossAppDomainDelegate is a good tool for threading across appdomain
boundaries.

HTH,
D. Swicegood

"Polaris" <et*******@hotmail.comwrote in message
news:14**********************************@microsof t.com...
Hi C# Experts:

I have 2 threads and I like to run them in seperate AppDomains.

In other words, I want to start 2 new AppDomains and then run a thread
within each of the AppDomains. How to do it?

Thanks
Polaris
Sep 6 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Doug Thews | last post: by
8 posts views Thread by wavemill | last post: by
4 posts views Thread by Mrinal Kamboj | last post: by
6 posts views Thread by Brian Gideon | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.