Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

What are two query techniques that you can use to maximize performance of your applications?

A1:

Two rules you should always keep in mind are to ask for only the columns you will work with and, more importantly, to ask for only the rows that will be displayed. Not doing so results in extra work for the server as well as consumption of extra resources on the client or middle- tier machine.

2:

Why might you not want to use command builders exposed by .NET Data Providers?

A2:

Although command builders are convenient from the perspective of generating insert, update, and delete commands for a data adapter, they incur an extra round trip to the database server. Although the round trip happens only once, command builders also don't use stored procedures, which not only provide better performance but also abstract the database schema and can be secured.

3:

What are two techniques for implementing multithreading in a .NET application?

A3:

The .NET Framework provides the classes of the System.Threading namespace in addition to asynchronous delegates to create multithreaded applications. Asynchronous delegates are used throughout the Framework and are more elegant because they allow arguments to be passed into the thread and don't force you to manipulate threads directly.

4:

Why might you need to use COM Interop?

A4:

COM Interop enables you to call COM components from managed code and managed components from COM code. The former scenario is more frequent because organizations typically have existing COM components deployed that encapsulate well- tested business logic and data access code. Using COM Interop with the OleDbDataAdapter enables you to retrieve ADO Recordset objects and use them to populate DataSet objects.

Exercise

Q1:

Create a console application that uses the asynchronous delegate pattern to call one of its private methods on a separate thread.

A1:

One possible solution to the exercise follows . By using breakpoints and noting the results in the command window, you should be able to understand how the asynchronous delegate pattern works.

 using System; using System.Threading; using System.Runtime.Remoting.Messaging; namespace AsyncTest {         /// <summary>         /// Summary description for Class1.         /// </summary>         class Class1         {          /// <summary>          /// The main entry point for the application.          /// </summary>          private delegate int AsyncOp(string arg1);          [STAThread]          static void Main(string[] args)          {          // Show the current thread           Console.WriteLine("Started on " + Thread.CurrentThread.GetHashCode());           // Setup the callback           AsyncCallback cb = new AsyncCallback(AsyncMethodDone);           //Call the method asynchronously           AsyncOp d = new AsyncOp(AsyncMethod);           d.BeginInvoke("some data",cb,null);           Console.ReadLine();          }          static private int AsyncMethod(string arg1)          {            // do the operation here, like get ADO.NET data            // perhaps returning the number of rows            return 5;          }          static private void AsyncMethodDone(IAsyncResult ar)          {            // Show the current thread            Console.WriteLine("Ended on " + Thread.CurrentThread.GetHashCode());            // Extract the delegate from the AsyncResult.            AsyncResult result = (AsyncResult)ar;            AsyncOp d = (AsyncOp)result.AsyncDelegate;            // End the operation and catch the return value            int i = d.EndInvoke(ar);            // Write out the return value            Console.WriteLine("Resulting in " + i);          }         } } 
for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net