Implementing service processes, threading and application domains in a .NET Framework application

These questions are based on 70-622CSHP – TS: Microsoft .NET Framework 2.0 – Application Development Foundation (C#.NET) Microsoft Self-Test Software Practice Test.


Objective: Implementing service processes, threading and application domains in a .NET Framework application
SubObjective: Develop multithreaded .NET Framework applications (Refer System.Threading namespace)


Item No. 70-536CSHP.2.2.4
Single Answer, Multiple Choice


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?



  1. ThreadPool.QueueUserWorkItem( Task1 );
    ThreadPool.QueueUserWorkItem( Task2 );
    ThreadPool.QueueUserWorkItem( Task3 );


  2. Thread th1 = new Thread( Task1 );
    Thread th2 = new Thread( Task2 );
    Thread th3 = new Thread( Task3 );
    th1.Start();
    th2.Start();
    th3.Start();


  3. ThreadPool thPool = new ThreadPool(“Current Application”);
    thPool.QueueUserWorkItem( Task1 );
    thPool.QueueUserWorkItem( Task2 );
    thPool.QueueUserWorkItem( Task3 );


  4. ThreadPool thPool = new ThreadPool(“Current Application”);
    Thread th1 = new Thread( Task1 );
    Thread th2 = new Thread( Task2 );
    Thread th3 = new Thread( Task3 );
    th1.StartInPool(thPool);
    th2.StartInPool(thPool);
    th3.StartInPool(thPool);

Answer:



  1. ThreadPool.QueueUserWorkItem( Task1 );
    ThreadPool.QueueUserWorkItem( Task2 );
    ThreadPool.QueueUserWorkItem( Task3 );

Tutorial:
You should use the following code to create and start the application threads:


ThreadPool.QueueUserWorkItem( Task1 );
ThreadPool.QueueUserWorkItem( Task2 );
ThreadPool.QueueUserWorkItem( Task3 );


This code uses the QueueUserWorkItem method of the ThreadPool class to add tasks to the current…


cmadmin

ABOUT THE AUTHOR

Posted in Uncategorized|

Comment:

Powered by WebDesk