472,985 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 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 7049
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.