473,473 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 7148
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the...
1
by: Daylor | last post by:
hi. i have application with 2 appdomain , and 2 threads (win32 threads(not logical threads)). i want to call the "remote" object on the second appdomain in async way, so the method will execute...
3
by: Keyee Hsu | last post by:
Hi, I have a C# app that creates an AppDomain, enters it, and spawns an asyn thread to do some work and then block itself. Upon the completion of the work, the async thread supposedly terminates,...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
8
by: wavemill | last post by:
This is my code: FileStream fs = new FileStream(@"C:\Documents and Settings\Berdoues\Mes documents\VisualStudioProjects\Application_Test_WindowsForm\LoadAssembly\CaptureControl.exe",FileMode.Open);...
5
by: Nak | last post by:
Hi there, I have a very simple console application that I'm trying to handle the thread exception on, as I understand it there is no Application object available to a console application, so I...
4
by: Mrinal Kamboj | last post by:
Hi , I had a doubt regarding a piece of code with me , that has to do with System.Threading.Thread class . In it user instantiates an array of Thread class and to all of them assign a method...
6
by: Brian Gideon | last post by:
How have you handled the finalization of thread-specific unmanaged resources? My question pertains specifically to using the DDEML which is a thread-specific API. In other words, every call to...
2
by: Artem | last post by:
When I use the method Thread.Abort, it only sends a request of aborting to OS to stop a thread. The thread itself isn't killed and allocated resources aren't released. I tried to run that thread...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.