How to: Create an Application Domain
A common language run-time host creates application domains automatically when they are needed. However, you can create your own application domains and load into them those assemblies that you want to manage personally. You can also create application domains from which you execute code. You
create a new application domain using one of the overloaded Create Domain
methods in the System.AppDomain
class. You can give the application domain a name and reference it by
that name.
You are an application developer for a company. You are creating a business logic component that requires long calculations. You identify several tasks within the application that can be done asynchronously. These tasks are interdependent and require complex synchronization techniques to manage efficiently. You decide to take advantage of the new thread management features in Microsoft .NET 2.0. Which code should you use to create and start the application threads?
Answer:
Tutorial: ThreadPool.QueueUserWorkItem( Task1 ); This code uses the QueueUserWorkItem method of the ThreadPool class to add tasks to the current application domain's thread pool. The QueueUserWorkItem method takes a WaitCallback delegate as an argument and manages the tasks using background threads. This allows the developer to concentrate on business logic and requires minimal synchronization code. You should not use either of the code fragments that instantiate the Thread objects explicitly. This will require excessive synchronization code to manage effectively. In this scenario, you should use the ThreadPool class to minimize the synchronization code. You should not use the code that instantiates a ThreadPool object because the ThreadPool class is a static class and cannot be instantiated. The methods of the ThreadPool class are all class members and do not require an instance to invoke. In this scenario, you should invoke the QueueUserWorkItem method on the ThreadPool class directly. Reference: certmag |