vb.net barcode generator open source PARALLEL PROGRAMMING in Visual C#.NET

Drawer Data Matrix ECC200 in Visual C#.NET PARALLEL PROGRAMMING

CHAPTER 24 PARALLEL PROGRAMMING
Painting Data Matrix 2d Barcode In C#
Using Barcode encoder for Visual Studio .NET Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
Recognize Data Matrix ECC200 In Visual C#
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
returning a result value, the exception is re-thrown. Here are the results of compiling and running Listing 24-15: ---- Exception Caught From Trigger Member ------ Exception type: System.AggregateException Press enter to finish Notice that the exception that was thrown by the CalculateSum method is wrapped in an AggregateException, which is a special kind of exception that can be used to bundle multiple exceptions together. The InnerExceptions property returns a collection of exceptions that you can use to get details of the exceptions thrown in the Task body. Here is an example applied to the catch clause in Listing 2415: try { long taskResult = myTask.Result; Console.WriteLine("Result: {0}", taskResult); } catch (AggregateException aggEx) { // get the inner exceptions foreach (Exception innerEx in aggEx.InnerExceptions) { Console.WriteLine("Inner Exception type: {0}", innerEx.GetType()); Console.WriteLine("Inner Exception message: {0}", innerEx.Message); } }
Encoding Data Matrix ECC200 In C#
Using Barcode maker for Visual Studio .NET Control to generate, create ECC200 image in Visual Studio .NET applications.
www.OnBarcode.com
Painting EAN128 In C#
Using Barcode generator for .NET Control to generate, create EAN128 image in .NET applications.
www.OnBarcode.com
Handling Exceptions from Multiple Tasks
Print Barcode In C#
Using Barcode encoder for .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
Print UPC Code In Visual C#.NET
Using Barcode creator for VS .NET Control to generate, create UPC Code image in Visual Studio .NET applications.
www.OnBarcode.com
If you are working with multiple Tasks and you have called the WaitAll method, any AggregateException that may be thrown will contain all of the exceptions that the individual Tasks have encountered. Iterating through the InnerExceptions collection will give you access to each original exception in turn, as demonstrated by Listing 24-16. Listing 24-16. Unpacking Exceptions from Multiple Tasks using System; using System.Threading.Tasks; class Listing 16 { static void Main(string[] args) { // create a collection to contain the Tasks Task<long>[] tasksArray = new Task<long>[4]; // create the tasks for (int i = 0; i < tasksArray.Length; i++) { tasksArray[i] = Task<long>.Factory.StartNew((stateObject) => {
Painting Code39 In Visual C#.NET
Using Barcode creator for .NET Control to generate, create Code 39 Extended image in Visual Studio .NET applications.
www.OnBarcode.com
Making Code 2 Of 7 In C#.NET
Using Barcode drawer for .NET framework Control to generate, create USD-4 image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 24 PARALLEL PROGRAMMING
Data Matrix 2d Barcode Maker In None
Using Barcode creation for Online Control to generate, create DataMatrix image in Online applications.
www.OnBarcode.com
Data Matrix Generator In Java
Using Barcode generation for BIRT reports Control to generate, create Data Matrix image in Eclipse BIRT applications.
www.OnBarcode.com
int taskID = (int)stateObject; long total = 0; for (int j = 0; j < int.MaxValue; j++) { total = CalculateSum(taskID, j, total); } return total; }, i); } try { // wait for all of the tasks to complete Task.WaitAll(tasksArray); } catch (AggregateException aggEx) { // enumerate the exceptions foreach (Exception innerEx in aggEx.InnerExceptions) { Console.WriteLine("Inner exception: {0} - {1}", innerEx.GetType(), innerEx.Message); } } // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); } public static long CalculateSum(int taskID, int x, long y) { if (taskID % 2 == 0 && x == 1000) { throw new ArgumentOutOfRangeException( string.Format("Exception for taskID {0}", taskID)); } else { return x + y; } } } This is a slightly more complicated example where the state object passed to each Task when it is created is used by the CalculateSum method to selectively throw exceptions. This means that of the four Tasks that are created in Listing 24-16, two of them will run to completion and two will cause exceptions to be thrown. The trigger member in Listing 24-16 is the WaitAll method, which means that the AggregateException that is re-thrown will contain two exceptions. Compiling and running Listing 24-16 produces the following results: Inner exception: System.ArgumentOutOfRangeException - Specified argument was out of the range of valid values. Parameter name: Exception for taskID 2 Inner exception: System.ArgumentOutOfRangeException - Specified argument was out of the range of valid values. Parameter name: Exception for taskID 0
Code 3 Of 9 Creation In Java
Using Barcode generator for Java Control to generate, create ANSI/AIM Code 39 image in Java applications.
www.OnBarcode.com
Code 3 Of 9 Decoder In VS .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
CHAPTER 24 PARALLEL PROGRAMMING
Encoding Data Matrix ECC200 In None
Using Barcode printer for Online Control to generate, create DataMatrix image in Online applications.
www.OnBarcode.com
Create Barcode In Java
Using Barcode printer for Eclipse BIRT Control to generate, create Barcode image in Eclipse BIRT applications.
www.OnBarcode.com
Press enter to finish
Barcode Creator In Java
Using Barcode generation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
ANSI/AIM Code 128 Scanner In VS .NET
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Dealing with Exceptions using Task Properties
Draw QR Code In Java
Using Barcode drawer for Android Control to generate, create Denso QR Bar Code image in Android applications.
www.OnBarcode.com
Encoding QR Code In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create QR Code 2d barcode image in Reporting Service applications.
www.OnBarcode.com
In the previous section, you used the state parameter to differentiate exceptions so that it was obvious which aggregated exception originated from which of the Tasks. This is not always possible (since you won t be able to insert the state object value into the message of exceptions thrown by other programmer s code) or desirable (because you will want to use the state object to pass more useful information to the Task body). An alternative way of processing exceptions is to use a trigger member to re-throw the exceptions, but use the individual Task properties to work out what went wrong, as illustrated by Listing 24-17. Listing 24-17. Dealing with Exceptions Using Properties using System; using System.Threading.Tasks; class Listing 17 { static void Main(string[] args) { // create a collection to contain the Tasks Task<long>[] tasksArray = new Task<long>[4]; // create the tasks for (int i = 0; i < tasksArray.Length; i++) { tasksArray[i] = Task<long>.Factory.StartNew((stateObject) => { int taskID = (int)stateObject; long total = 0; for (int j = 0; j < int.MaxValue; j++) { total = CalculateSum(taskID, j, total); } return total; }, i); } try { // wait for all of the tasks to complete Task.WaitAll(tasksArray); } catch (AggregateException) { // work through the set of Tasks and use the properties // to determine what happened for (int i = 0; i < tasksArray.Length; i++) { // get the exception at the current index Task<long> currentTask = tasksArray[i]; if (currentTask.IsFaulted) { Console.WriteLine("Task {0} encountered an exception", i);
Printing UPC-A In None
Using Barcode encoder for Font Control to generate, create UPC Code image in Font applications.
www.OnBarcode.com
UPC A Generator In .NET Framework
Using Barcode generator for VS .NET Control to generate, create UPC-A image in Visual Studio .NET applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.