AppDomain and Multi-Threading

K

Kai Iske

Hi,

following situation (this is still .NET 1.1 - *sigh*)

For a scheduling application, I create a Thread for every task that is
due to be executed. Once a task execution is due, a running Thread
will be created. The runner thread in turn will instantiate a
TaskRunner object in a new AppDomain, so it is like that. The
TaskRunner then instantiates the Task class and calls a method on an
interface:

1. Create New Thread
2. Thread creates new AppDomain
3. TaskRunner is created in new AppDomain
4. TaskRunner instantiates task class and executes interface method

2. - 4. all happen on the same (newly created thread)

After the TaskRunner has executed the task method, it cleans up,
however when the Thread calls to unload the AppDomain it previously
created, the whole thread is aborted and no code is executed anymore
after the unload.

I don't quite understand why this would happen. My worker thread runs
on the main AppDomain and creates/unloads a child AppDomain. I wonder
why unloading that child AppDomain would kill my worker thread.

Any help would be highly appreciated.

Thanks

Kai
 
R

Ross Presser

Hi,

following situation (this is still .NET 1.1 - *sigh*)

For a scheduling application, I create a Thread for every task that is
due to be executed. Once a task execution is due, a running Thread
will be created. The runner thread in turn will instantiate a
TaskRunner object in a new AppDomain, so it is like that. The
TaskRunner then instantiates the Task class and calls a method on an
interface:

1. Create New Thread
2. Thread creates new AppDomain
3. TaskRunner is created in new AppDomain
4. TaskRunner instantiates task class and executes interface method

2. - 4. all happen on the same (newly created thread)

After the TaskRunner has executed the task method, it cleans up,
however when the Thread calls to unload the AppDomain it previously
created, the whole thread is aborted and no code is executed anymore
after the unload.

I don't quite understand why this would happen. My worker thread runs
on the main AppDomain and creates/unloads a child AppDomain. I wonder
why unloading that child AppDomain would kill my worker thread.

Any help would be highly appreciated.

Is an exception thrown when you unload? I'd start there, put a try/
catch around the unload in the thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top