|
1 | 1 | // <Snippet2>
|
2 | 2 | using System;
|
3 | 3 | using System.Globalization;
|
4 |
| -using System.Runtime.Versioning; |
5 | 4 | using System.Threading;
|
6 | 5 | using System.Threading.Tasks;
|
7 | 6 |
|
8 |
| -public class Example |
| 7 | +public class AsyncCultureEx |
9 | 8 | {
|
10 |
| - public static void Main() |
11 |
| - { |
12 |
| - decimal[] values = { 163025412.32m, 18905365.59m }; |
13 |
| - string formatString = "C2"; |
14 |
| - Func<String> formatDelegate = () => { string output = String.Format("Formatting using the {0} culture on thread {1}.\n", |
15 |
| - CultureInfo.CurrentCulture.Name, |
16 |
| - Thread.CurrentThread.ManagedThreadId); |
17 |
| - foreach (var value in values) |
18 |
| - output += String.Format("{0} ", value.ToString(formatString)); |
| 9 | + public static void Main() |
| 10 | + { |
| 11 | + decimal[] values = { 163025412.32m, 18905365.59m }; |
| 12 | + string formatString = "C2"; |
| 13 | + Func<String> formatDelegate = () => |
| 14 | + { |
| 15 | + string output = String.Format("Formatting using the {0} culture on thread {1}.\n", |
| 16 | + CultureInfo.CurrentCulture.Name, |
| 17 | + Thread.CurrentThread.ManagedThreadId); |
| 18 | + foreach (var value in values) |
| 19 | + output += String.Format("{0} ", value.ToString(formatString)); |
19 | 20 |
|
20 |
| - output += Environment.NewLine; |
21 |
| - return output; |
22 |
| - }; |
| 21 | + output += Environment.NewLine; |
| 22 | + return output; |
| 23 | + }; |
23 | 24 |
|
24 |
| - Console.WriteLine("The example is running on thread {0}", |
25 |
| - Thread.CurrentThread.ManagedThreadId); |
26 |
| - // Make the current culture different from the system culture. |
27 |
| - Console.WriteLine("The current culture is {0}", |
28 |
| - CultureInfo.CurrentCulture.Name); |
29 |
| - if (CultureInfo.CurrentCulture.Name == "fr-FR") |
30 |
| - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); |
31 |
| - else |
32 |
| - Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); |
| 25 | + Console.WriteLine("The example is running on thread {0}", |
| 26 | + Thread.CurrentThread.ManagedThreadId); |
| 27 | + // Make the current culture different from the system culture. |
| 28 | + Console.WriteLine("The current culture is {0}", |
| 29 | + CultureInfo.CurrentCulture.Name); |
| 30 | + if (CultureInfo.CurrentCulture.Name == "fr-FR") |
| 31 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); |
| 32 | + else |
| 33 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); |
33 | 34 |
|
34 |
| - Console.WriteLine("Changed the current culture to {0}.\n", |
35 |
| - CultureInfo.CurrentCulture.Name); |
| 35 | + Console.WriteLine("Changed the current culture to {0}.\n", |
| 36 | + CultureInfo.CurrentCulture.Name); |
36 | 37 |
|
37 |
| - // Execute the delegate synchronously. |
38 |
| - Console.WriteLine("Executing the delegate synchronously:"); |
39 |
| - Console.WriteLine(formatDelegate()); |
| 38 | + // Execute the delegate synchronously. |
| 39 | + Console.WriteLine("Executing the delegate synchronously:"); |
| 40 | + Console.WriteLine(formatDelegate()); |
40 | 41 |
|
41 |
| - // Call an async delegate to format the values using one format string. |
42 |
| - Console.WriteLine("Executing a task asynchronously:"); |
43 |
| - var t1 = Task.Run(formatDelegate); |
44 |
| - Console.WriteLine(t1.Result); |
| 42 | + // Call an async delegate to format the values using one format string. |
| 43 | + Console.WriteLine("Executing a task asynchronously:"); |
| 44 | + var t1 = Task.Run(formatDelegate); |
| 45 | + Console.WriteLine(t1.Result); |
45 | 46 |
|
46 |
| - Console.WriteLine("Executing a task synchronously:"); |
47 |
| - var t2 = new Task<String>(formatDelegate); |
48 |
| - t2.RunSynchronously(); |
49 |
| - Console.WriteLine(t2.Result); |
50 |
| - } |
| 47 | + Console.WriteLine("Executing a task synchronously:"); |
| 48 | + var t2 = new Task<String>(formatDelegate); |
| 49 | + t2.RunSynchronously(); |
| 50 | + Console.WriteLine(t2.Result); |
| 51 | + } |
51 | 52 | }
|
52 | 53 | // The example displays the following output:
|
53 | 54 | // The example is running on thread 1
|
|
0 commit comments