├── .gitignore
├── AsyncConceptualSimplification
├── App.config
├── AsyncOverSimplified.csproj
├── AsyncOverSimplified.sln
├── MoreRealisticAsyncWorker.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── SimpleAsyncWorker.cs
├── AsyncInfiniteLoops
├── AsyncInfiniteLoops.sln
├── AsyncInfiniteLoops
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AsyncInfiniteLoops.csproj
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ └── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
└── README.md
├── AsyncIsNotParallel
├── AsyncIsNotParallel.sln
├── AsyncIsNotParallel
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AsyncIsNotParallel.csproj
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ └── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
└── README.md
├── ConfigureAwaitBehavior
├── ExtremeConfigAwait.sln
├── ExtremeConfigAwaitLibrary
│ ├── AwaitableExtensions.cs
│ ├── Case0.cs
│ ├── Case1.cs
│ ├── Case2.cs
│ ├── Case3.cs
│ ├── Case4.cs
│ ├── Diag.cs
│ ├── ExtremeConfigAwaitLibrary.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── SynchronizationContextRemover.cs
└── ExtremeConfigAwaitWPFSample
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── ExtremeConfigAwaitWPFSample.csproj
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ └── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/AsyncOverSimplified.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {0025FD29-CF12-4A4B-B12D-C116B5347955}
8 | Exe
9 | Properties
10 | AsyncOverSimplified
11 | AsyncOverSimplified
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
62 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/AsyncOverSimplified.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncOverSimplified", "AsyncOverSimplified.csproj", "{0025FD29-CF12-4A4B-B12D-C116B5347955}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {0025FD29-CF12-4A4B-B12D-C116B5347955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {0025FD29-CF12-4A4B-B12D-C116B5347955}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {0025FD29-CF12-4A4B-B12D-C116B5347955}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {0025FD29-CF12-4A4B-B12D-C116B5347955}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/MoreRealisticAsyncWorker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace AsyncOverSimplified
5 | {
6 | public class MoreRealisticAsyncWorker
7 | {
8 | public async Task DoWork()
9 | {
10 | int count = 0;
11 |
12 |
13 | int resultX = await GetCountAsync("x");
14 | count = count + resultX;
15 | Console.WriteLine("X Count is " + count);
16 |
17 |
18 | int resultY = await GetCountAsync("y");
19 | count = count + resultY;
20 | Console.WriteLine("Y Count is " + count);
21 |
22 |
23 | int resultZ = await GetCountAsync("z");
24 | count = count + resultZ;
25 | Console.WriteLine("Z Count is " + count);
26 |
27 | return count;
28 | }
29 |
30 | public async Task DoWorkExplicitTasks()
31 | {
32 | int count = 0;
33 |
34 | Task taskX = GetCountAsync("x");
35 | int resultX = await taskX;
36 | count = count + resultX;
37 | Console.WriteLine("X Count is " + count);
38 |
39 | Task taskY = GetCountAsync("y");
40 | int resultY = await taskY;
41 | count = count + resultY;
42 | Console.WriteLine("Y Count is " + count);
43 |
44 | Task taskZ = GetCountAsync("z");
45 | int resultZ = await taskZ;
46 | count = count + resultZ;
47 | Console.WriteLine("Z Count is " + count);
48 |
49 | return count;
50 | }
51 |
52 | public Task DoWorkWithoutAwait()
53 | {
54 | int count = 0;
55 | Task final;
56 |
57 | Task startTask = GetCountAsync("x");
58 |
59 | final =
60 | startTask.ContinueWith(taskX =>
61 | {
62 | int resultX = taskX.Result;
63 | count = count + resultX;
64 | Console.WriteLine("X Count is " + count);
65 | })
66 | .ContinueWith(tmp =>
67 | {
68 | return GetCountAsync("y").Result;
69 | })
70 | .ContinueWith(ty =>
71 | {
72 | int resultY = ty.Result;
73 | count = count + resultY;
74 | Console.WriteLine("Y Count is " + count);
75 | })
76 | .ContinueWith(tmp =>
77 | {
78 | return GetCountAsync("z").Result;
79 | })
80 | .ContinueWith(tz =>
81 | {
82 | int resultZ = tz.Result;
83 | count = count + resultZ;
84 | Console.WriteLine("Z Count is " + count);
85 | })
86 | .ContinueWith(_ => count);
87 |
88 | return final;
89 | }
90 |
91 | ///
92 | /// This method just returns a number for demonstration purposes
93 | /// It doesnt actually count anything
94 | ///
95 | ///
96 | ///
97 | private async Task GetCountAsync(string v)
98 | {
99 | await Task.Delay(100);
100 | return (int)v[0];
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AsyncOverSimplified
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | SimpleMainAsync().Wait();
10 | //ComplexMainAsync().Wait();
11 | }
12 |
13 | ///
14 | /// Runs all 3 variations of the Simple code to ensure
15 | /// they all have the same result
16 | ///
17 | ///
18 | static async Task SimpleMainAsync()
19 | {
20 | var worker = new SimpleAsyncWorker();
21 | await worker.DoWork();
22 | await worker.DoWorkExplicitTasks();
23 | await worker.DoWorkWithoutAwait();
24 | }
25 |
26 | ///
27 | /// Runs all 3 variations of the MoreRealistic code to ensure
28 | /// they all have the same result
29 | ///
30 | ///
31 | static async Task MoreRealisticMainAsync()
32 | {
33 | var worker = new MoreRealisticAsyncWorker();
34 | await worker.DoWork();
35 | await worker.DoWorkExplicitTasks();
36 | await worker.DoWorkWithoutAwait();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AsyncOverSimplified")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AsyncOverSimplified")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0025fd29-cf12-4a4b-b12d-c116b5347955")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/AsyncConceptualSimplification/SimpleAsyncWorker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace AsyncOverSimplified
5 | {
6 | public class SimpleAsyncWorker
7 | {
8 | public async Task DoWork()
9 | {
10 | int count = 0;
11 |
12 | int result = await GetCountAsync("x");
13 | count = count + result;
14 | Console.WriteLine("X Count is " + count);
15 | return count;
16 | }
17 |
18 | public async Task DoWorkExplicitTasks()
19 | {
20 | int count = 0;
21 |
22 | Task countTask = GetCountAsync("x");
23 | int result = await countTask;
24 | count = count + result;
25 | Console.WriteLine("X Count is " + count);
26 | return count;
27 | }
28 |
29 | public Task DoWorkWithoutAwait()
30 | {
31 | int count = 0;
32 |
33 | Task countTask = GetCountAsync("x");
34 |
35 | Task final =
36 | countTask.ContinueWith(_ =>
37 | {
38 | int result = countTask.Result;
39 | count = count + result;
40 | Console.WriteLine("X Count is " + count);
41 | return count;
42 | });
43 |
44 | return final;
45 | }
46 |
47 |
48 | private async Task GetCountAsync(string v)
49 | {
50 | await Task.Delay(100);
51 | return (int)v[0];
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncInfiniteLoops", "AsyncInfiniteLoops\AsyncInfiniteLoops.csproj", "{5A951FD6-CF7B-4B65-ADCC-D09317461F57}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {5A951FD6-CF7B-4B65-ADCC-D09317461F57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {5A951FD6-CF7B-4B65-ADCC-D09317461F57}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {5A951FD6-CF7B-4B65-ADCC-D09317461F57}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {5A951FD6-CF7B-4B65-ADCC-D09317461F57}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace AsyncInfiniteLoops
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/AsyncInfiniteLoops.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5A951FD6-CF7B-4B65-ADCC-D09317461F57}
8 | WinExe
9 | Properties
10 | AsyncInfiniteLoops
11 | WpfApplication19
12 | v4.5
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | 4.0
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | MSBuild:Compile
54 | Designer
55 |
56 |
57 | MSBuild:Compile
58 | Designer
59 |
60 |
61 | App.xaml
62 | Code
63 |
64 |
65 | MainWindow.xaml
66 | Code
67 |
68 |
69 |
70 |
71 | Code
72 |
73 |
74 | True
75 | True
76 | Resources.resx
77 |
78 |
79 | True
80 | Settings.settings
81 | True
82 |
83 |
84 | ResXFileCodeGenerator
85 | Resources.Designer.cs
86 |
87 |
88 | SettingsSingleFileGenerator
89 | Settings.Designer.cs
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
104 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using System.Windows;
4 | using System.Windows.Threading;
5 |
6 | namespace AsyncInfiniteLoops
7 | {
8 | ///
9 | /// Interaction logic for MainWindow.xaml
10 | ///
11 | public partial class MainWindow : Window
12 | {
13 | public MainWindow()
14 | {
15 | InitializeComponent();
16 | }
17 |
18 | private async Task DoWorkAsyncInfiniteLoop()
19 | {
20 | while (true)
21 | {
22 | // do the work in the loop
23 | string newData = DateTime.Now.ToLongTimeString();
24 |
25 | // update the UI
26 | txtTicks.Text = "ASYNC LOOP - " + newData;
27 |
28 | // don't run again for at least 200 milliseconds
29 | await Task.Delay(200);
30 | }
31 | }
32 |
33 | private void bttnStart_Click(object sender, RoutedEventArgs e)
34 | {
35 | //DoWorkPollingTask();
36 | //DoWorkTimer();
37 |
38 | // invoke RunTimer but DO NOT await it
39 | DoWorkAsyncInfiniteLoop();
40 | }
41 |
42 | #region POLLINGTASK METHOD
43 | void DoWorkPollingTask()
44 | {
45 | Task.Run(async () =>
46 | {
47 | while (true)
48 | {
49 | // do the work in the loop
50 | string newData = DateTime.Now.ToLongTimeString();
51 |
52 | // marshal back over to the UI thread to update the UI
53 | Dispatcher.Invoke(() => txtTicks.Text = "TASK - " + newData);
54 |
55 | // don't run again for at least 200 milliseconds
56 | await Task.Delay(200);
57 | }
58 | });
59 | }
60 | #endregion
61 |
62 | #region DISPATCHERTIMER METHOD
63 | DispatcherTimer _timer = new DispatcherTimer();
64 |
65 | void DoWorkTimer()
66 | {
67 | // execute at a minimum of 200 milliseconds between ticks
68 | _timer.Interval = TimeSpan.FromMilliseconds(200);
69 | _timer.Tick += _timer_Tick;
70 | _timer.IsEnabled = true;
71 | }
72 |
73 | void _timer_Tick(object sender, EventArgs e)
74 | {
75 | // do the work in the loop
76 | string newData = DateTime.Now.ToLongTimeString();
77 |
78 | // update the UI on the UI thread
79 | txtTicks.Text = "TIMER - " + newData;
80 | }
81 | #endregion
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WpfApplication19")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WpfApplication19")]
15 | [assembly: AssemblyCopyright("Copyright © 2016")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AsyncInfiniteLoops.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AsyncInfiniteLoops.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AsyncInfiniteLoops.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/AsyncInfiniteLoops/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/AsyncInfiniteLoops/README.md:
--------------------------------------------------------------------------------
1 | # blog-examples
2 | This folder contains example code from the blog post https://blogs.msdn.microsoft.com/benwilli/2016/06/30/asynchronous-infinite-loops-instead-of-timers/
3 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncIsNotParallel", "AsyncIsNotParallel\AsyncIsNotParallel.csproj", "{906B9D08-5EDD-4755-9C59-4D327A2B334C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {906B9D08-5EDD-4755-9C59-4D327A2B334C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {906B9D08-5EDD-4755-9C59-4D327A2B334C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {906B9D08-5EDD-4755-9C59-4D327A2B334C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {906B9D08-5EDD-4755-9C59-4D327A2B334C}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace AsyncIsNotParallel
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/AsyncIsNotParallel.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {906B9D08-5EDD-4755-9C59-4D327A2B334C}
8 | WinExe
9 | Properties
10 | AsyncIsNotParallel
11 | AsyncIsNotParallel
12 | v4.5.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | App.xaml
64 | Code
65 |
66 |
67 | MainWindow.xaml
68 | Code
69 |
70 |
71 |
72 |
73 | Code
74 |
75 |
76 | True
77 | True
78 | Resources.resx
79 |
80 |
81 | True
82 | Settings.settings
83 | True
84 |
85 |
86 | ResXFileCodeGenerator
87 | Resources.Designer.cs
88 |
89 |
90 | SettingsSingleFileGenerator
91 | Settings.Designer.cs
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
106 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Media;
8 | using System.Windows.Shapes;
9 |
10 | namespace AsyncIsNotParallel
11 | {
12 | ///
13 | /// Interaction logic for MainWindow.xaml
14 | ///
15 | public partial class MainWindow : Window
16 | {
17 | public MainWindow()
18 | {
19 | InitializeComponent();
20 | }
21 |
22 | Stopwatch sw = new Stopwatch();
23 | private async void bttnStart_Click(object sender, RoutedEventArgs e)
24 | {
25 | txtStatus.Text = "Started";
26 | sw.Restart();
27 | Task t1 = DoWorkAsync(Colors.Red, 0, 200);
28 | Task t2 = DoWorkAsync(Colors.Blue, 1, 300);
29 | Task t3 = DoWorkAsync(Colors.Green, 2, 500);
30 | await Task.WhenAll(t1, t2, t3);
31 | sw.Stop();
32 | txtStatus.Text = $"Finished after {sw.ElapsedMilliseconds}";
33 | }
34 |
35 | private void bttnClear_Click(object sender, RoutedEventArgs e)
36 | {
37 | theRootCanvas.Children.Clear();
38 | }
39 |
40 | private async Task DoWorkAsync(Color color, int column, int delay)
41 | {
42 | for (int i = 0; i < 5; i++)
43 | {
44 | // perform some asynchronous task in various ways
45 | // await Task.Yield(); // yields immediately
46 | // await Task.Delay(0); // continues synchronously
47 | // await Task.Delay(100); // continues asynchronously on UI thread
48 | // await Task.Delay(0).ConfigureAwait(false); // continues synchronously
49 | // await Task.Delay(100).ConfigureAwait(false); // continues asynchronously on any thread
50 |
51 | var startTime = sw.ElapsedMilliseconds;
52 |
53 | // spin here for 'delay' milliseconds just to keep busy
54 | while (sw.ElapsedMilliseconds < startTime + delay) { /* do nothing */ }
55 |
56 | var endTime = sw.ElapsedMilliseconds;
57 |
58 | int threadId = Thread.CurrentThread.ManagedThreadId;
59 |
60 | Dispatcher.BeginInvoke((Action)(() => AddTimeRectangle(
61 | startTime, endTime, color, column, threadId)));
62 | }
63 | }
64 |
65 | ///
66 | /// add a rectangle that whose height & position represents the start and end time
67 | /// of an activity
68 | ///
69 | ///
70 | ///
71 | ///
72 | ///
73 | private void AddTimeRectangle(double startTime, double endTime, Color color, int column, int threadId)
74 | {
75 | const int columnWidth = 50;
76 | Debug.WriteLine("Adding Rect {0} {1} {2} from thread:{3}", startTime, endTime, color, threadId);
77 |
78 | double left = column * (columnWidth * 2 / 3);
79 | double height = endTime - startTime;
80 |
81 | Rectangle r = new Rectangle()
82 | {
83 | Fill = new SolidColorBrush(color),
84 | Width = columnWidth,
85 | Height = height,
86 | };
87 | Canvas.SetLeft(r, left);
88 | Canvas.SetTop(r, startTime);
89 |
90 | theRootCanvas.Children.Add(r);
91 |
92 | if (theRootCanvas.Height < endTime)
93 | {
94 | theRootCanvas.Height = endTime;
95 | }
96 | if (theRootCanvas.Width < left + columnWidth)
97 | {
98 | theRootCanvas.Width = left + columnWidth;
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("AsyncIsNotParallel")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("AsyncIsNotParallel")]
15 | [assembly: AssemblyCopyright("Copyright © 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AsyncIsNotParallel.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AsyncIsNotParallel.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AsyncIsNotParallel.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/AsyncIsNotParallel/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/AsyncIsNotParallel/README.md:
--------------------------------------------------------------------------------
1 | # blog-examples
2 | This folder contains example code from the blog post http://blogs.msdn.com/b/benwilli/archive/2015/09/10/tasks-are-still-not-threads-and-async-is-not-parallel.aspx
3 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwait.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtremeConfigAwaitLibrary", "ExtremeConfigAwaitLibrary\ExtremeConfigAwaitLibrary.csproj", "{BCF619D1-C3A0-41AD-A74C-A999204C3081}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtremeConfigAwaitWPFSample", "ExtremeConfigAwaitWPFSample\ExtremeConfigAwaitWPFSample.csproj", "{EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {BCF619D1-C3A0-41AD-A74C-A999204C3081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {BCF619D1-C3A0-41AD-A74C-A999204C3081}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {BCF619D1-C3A0-41AD-A74C-A999204C3081}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {BCF619D1-C3A0-41AD-A74C-A999204C3081}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/AwaitableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace ExtremeConfigAwait
7 | {
8 | public static class AwaitableExtensions
9 | {
10 | static public ConfiguredTaskAwaitable PrintContext(this ConfiguredTaskAwaitable t, [CallerMemberName]string callerName = null, [CallerLineNumber]int line = 0)
11 | {
12 | PrintContext(callerName, line);
13 | return t;
14 | }
15 |
16 | static public Task PrintContext(this Task t, [CallerMemberName]string callerName = null, [CallerLineNumber]int line = 0)
17 | {
18 | PrintContext(callerName, line);
19 | return t;
20 | }
21 |
22 | static private void PrintContext([CallerMemberName]string callerName = null, [CallerLineNumber]int line = 0)
23 | {
24 | var ctx = SynchronizationContext.Current;
25 | if (ctx != null)
26 | {
27 | Console.WriteLine("{0}:{1:D4} await context will be {2}:", callerName, line, ctx);
28 | Console.WriteLine(" TSCHED:{0}", TaskScheduler.Current);
29 | }
30 | else
31 | {
32 | Console.WriteLine("{0}:{1:D4} await context will be ", callerName, line);
33 | Console.WriteLine(" TSCHED:{0}", TaskScheduler.Current);
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Case0.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 |
4 | namespace ExtremeConfigAwait
5 | {
6 | public class Case0
7 | {
8 | public async Task Run()
9 | {
10 | // regular async calls with no use of ConfigureAwait(false)
11 | // will use the default synchronization context
12 | Diag.PrintContext("ENTER");
13 | await WorkWithoutCA();
14 | Diag.PrintContext("EXIT");
15 | }
16 |
17 | const int cycleCount = 15000;
18 |
19 | private async Task WorkWithoutCA()
20 | {
21 | Diag.PrintContext("ENTER");
22 |
23 | await DoWorkAsync(cycleCount).PrintContext();
24 | await DoWorkAsync(cycleCount).PrintContext();
25 | await DoWorkAsync(cycleCount).PrintContext();
26 |
27 | Diag.PrintContext("EXIT");
28 | }
29 |
30 | private async Task DoWorkAsync(uint cycles)
31 | {
32 | Diag.PrintContext("ENTER");
33 | await BlockingWorkAsync(cycles).PrintContext();
34 | Diag.PrintContext("EXIT");
35 | }
36 |
37 | private async Task BlockingWorkAsync(uint cycles)
38 | {
39 | // Perform both async blocking and synchronous blocking
40 | Diag.PrintContext("ENTER");
41 | await Task.Delay(1000).PrintContext();
42 |
43 | Thread.Sleep(1000);
44 |
45 | await Task.Delay(1000).PrintContext();
46 | Diag.PrintContext("EXIT");
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Case1.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 |
4 | namespace ExtremeConfigAwait
5 | {
6 | public class Case1
7 | {
8 | public async Task Run()
9 | {
10 | // async calls with just the initial method's awaits marked
11 | // with ConfigureAwait(false)
12 | // will try to not use the default synchronization context
13 | Diag.PrintContext("ENTER");
14 | await WorkWithShallowCA();
15 | Diag.PrintContext("EXIT");
16 | }
17 |
18 | const int cycleCount = 15000;
19 |
20 | private async Task WorkWithShallowCA()
21 | {
22 | // only has ConfigureAwait at this level, children do not.
23 | Diag.PrintContext("ENTER");
24 |
25 | await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);
26 | await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);
27 | await DoWorkAsync(cycleCount).PrintContext().ConfigureAwait(false);
28 |
29 | Diag.PrintContext("EXIT");
30 | }
31 |
32 | private async Task DoWorkAsync(uint cycles)
33 | {
34 | Diag.PrintContext("ENTER");
35 | await BlockingWorkAsync(cycles).PrintContext();
36 | Diag.PrintContext("EXIT");
37 | }
38 |
39 | private async Task BlockingWorkAsync(uint cycles)
40 | {
41 | // Perform both async blocking and synchronous blocking
42 | Diag.PrintContext("ENTER");
43 | await Task.Delay(1000).PrintContext();
44 |
45 | Thread.Sleep(1000);
46 |
47 | await Task.Delay(1000).PrintContext();
48 | Diag.PrintContext("EXIT");
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Case2.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 |
4 | namespace ExtremeConfigAwait
5 | {
6 | public class Case2
7 | {
8 | public async Task Run()
9 | {
10 | // async calls with all awaits marked with ConfigureAwait(false)
11 | // will try to not use the default synchronization context
12 | Diag.PrintContext("ENTER");
13 | await WorkWithFullCA();
14 | Diag.PrintContext("EXIT");
15 | }
16 |
17 | const int cycleCount = 15000;
18 |
19 | private async Task WorkWithFullCA()
20 | {
21 | Diag.PrintContext("ENTER");
22 |
23 | await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);
24 | await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);
25 | await DoWorkAsyncCA(cycleCount).PrintContext().ConfigureAwait(false);
26 |
27 | Diag.PrintContext("EXIT");
28 | }
29 |
30 | private async Task DoWorkAsyncCA(uint cycles)
31 | {
32 | Diag.PrintContext("ENTER");
33 | await BlockingWorkAsyncCA(cycles).PrintContext().ConfigureAwait(false);
34 | Diag.PrintContext("EXIT");
35 | }
36 |
37 | private async Task BlockingWorkAsyncCA(uint cycles)
38 | {
39 | // Perform both async blocking and synchronous blocking
40 | Diag.PrintContext("ENTER");
41 |
42 | await Task.Delay(1000).PrintContext().ConfigureAwait(false);
43 |
44 | Thread.Sleep(1000);
45 |
46 | await Task.Delay(1000).PrintContext().ConfigureAwait(false);
47 | Diag.PrintContext("EXIT");
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Case3.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 |
5 | namespace ExtremeConfigAwait
6 | {
7 | public class Case3
8 | {
9 |
10 | public async Task Run()
11 | {
12 | Diag.PrintContext("ENTER");
13 | await WorkWithoutCA();
14 | Diag.PrintContext("EXIT");
15 | }
16 |
17 | const int cycleCount = 15000;
18 |
19 | private async Task WorkWithoutCA()
20 | {
21 | Diag.PrintContext("ENTER");
22 | await new SynchronizationContextRemover(); // this await strips the
23 | // SynchronizationContext for
24 | await DoWorkAsync(cycleCount).PrintContext(); // the rest of the this method
25 | await DoWorkAsync(cycleCount).PrintContext();
26 | await DoWorkAsync(cycleCount).PrintContext();
27 |
28 | Diag.PrintContext("EXIT");
29 | }
30 |
31 | private async Task DoWorkAsync(uint cycles)
32 | {
33 | Diag.PrintContext("ENTER");
34 | await BlockingWorkAsync(cycles).PrintContext();
35 | Diag.PrintContext("EXIT");
36 | }
37 |
38 | private async Task BlockingWorkAsync(uint cycles)
39 | {
40 | // Perform both async blocking and synchronous blocking
41 | Diag.PrintContext("ENTER");
42 | await Task.Delay(1000).PrintContext();
43 |
44 | Thread.Sleep(1000);
45 |
46 | await Task.Delay(1000).PrintContext();
47 | Diag.PrintContext("EXIT");
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Case4.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 |
4 | namespace ExtremeConfigAwait
5 | {
6 | public class Case4
7 | {
8 | public async Task Run()
9 | {
10 | // async calls run on a completely different thread (which does
11 | // not capture the original SynchronizationContext)
12 | Diag.PrintContext("ENTER");
13 | await Task.Run(() => WorkWithoutCA());
14 | Diag.PrintContext("EXIT");
15 | }
16 |
17 | const int cycleCount = 15000;
18 |
19 | private async Task WorkWithoutCA()
20 | {
21 | Diag.PrintContext("ENTER");
22 |
23 | await DoWorkAsync(cycleCount).PrintContext();
24 | await DoWorkAsync(cycleCount).PrintContext();
25 | await DoWorkAsync(cycleCount).PrintContext();
26 |
27 | Diag.PrintContext("EXIT");
28 | }
29 |
30 | private async Task DoWorkAsync(uint cycles)
31 | {
32 | Diag.PrintContext("ENTER");
33 | await BlockingWorkAsync(cycles).PrintContext();
34 | Diag.PrintContext("EXIT");
35 | }
36 |
37 | private async Task BlockingWorkAsync(uint cycles)
38 | {
39 | // Perform both async blocking and synchronous blocking
40 | Diag.PrintContext("ENTER");
41 | await Task.Delay(1000).PrintContext();
42 |
43 | Thread.Sleep(1000);
44 |
45 | await Task.Delay(1000).PrintContext();
46 | Diag.PrintContext("EXIT");
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Diag.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.CompilerServices;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace ExtremeConfigAwait
10 | {
11 | static public class Diag
12 | {
13 | static public void PrintContext(string message, [CallerMemberName]string callerName = null)
14 | {
15 |
16 | var ctx = SynchronizationContext.Current;
17 | if (ctx != null)
18 | {
19 |
20 | Console.WriteLine("{0}: {1} 0x{2:X8} TID:{3} TSCHED:0x{4}", callerName, message, ctx.GetHashCode(), Thread.CurrentThread.ManagedThreadId, TaskScheduler.Current);
21 | }
22 | else
23 | {
24 | Console.WriteLine("{0}: {1} TID:{2} TSCHED:{3}", callerName, message, Thread.CurrentThread.ManagedThreadId, TaskScheduler.Current);
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/ExtremeConfigAwaitLibrary.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {BCF619D1-C3A0-41AD-A74C-A999204C3081}
8 | Library
9 | Properties
10 | ExtremeConfigAwaitLibrary
11 | ExtremeConfigAwaitLibrary
12 | v4.6
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
62 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("YieldContextLibrary")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("YieldContextLibrary")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("bcf619d1-c3a0-41ad-a74c-a999204c3081")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitLibrary/SynchronizationContextRemover.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading;
4 |
5 | namespace ExtremeConfigAwait
6 | {
7 | public struct SynchronizationContextRemover : INotifyCompletion
8 | {
9 | public bool IsCompleted
10 | {
11 | get { return SynchronizationContext.Current == null; }
12 | }
13 |
14 | public void OnCompleted(Action continuation)
15 | {
16 | var prevContext = SynchronizationContext.Current;
17 | try
18 | {
19 | SynchronizationContext.SetSynchronizationContext(null);
20 | continuation();
21 | }
22 | finally
23 | {
24 | SynchronizationContext.SetSynchronizationContext(prevContext);
25 | }
26 | }
27 |
28 | public SynchronizationContextRemover GetAwaiter()
29 | {
30 | return this;
31 | }
32 |
33 | public void GetResult()
34 | {
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace ExtremeConfigAwaitWPFSample
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/ExtremeConfigAwaitWPFSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EDFBAF7A-4C07-46C0-8525-D78A77D91B4C}
8 | WinExe
9 | Properties
10 | ExtremeConfigAwaitWPFSample
11 | ExtremeConfigAwaitWPFSample
12 | v4.6
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | MSBuild:Compile
61 | Designer
62 |
63 |
64 | App.xaml
65 | Code
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 | SettingsSingleFileGenerator
92 | Settings.Designer.cs
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | {bcf619d1-c3a0-41ad-a74c-a999204c3081}
102 | ExtremeConfigAwaitLibrary
103 |
104 |
105 |
106 |
113 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | 0
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 | using System.Windows.Threading;
4 | using ExtremeConfigAwait;
5 |
6 | namespace ExtremeConfigAwaitWPFSample
7 | {
8 | ///
9 | /// Interaction logic for MainWindow.xaml
10 | ///
11 | public partial class MainWindow : Window
12 | {
13 | public MainWindow()
14 | {
15 | InitializeComponent();
16 | Loaded += MainWindow_Loaded;
17 | }
18 |
19 | DispatcherTimer _timer = new DispatcherTimer();
20 | private void MainWindow_Loaded(object sender, RoutedEventArgs e)
21 | {
22 | _timer.Interval = TimeSpan.FromMilliseconds(100);
23 | _timer.Tick += _timer_Tick;
24 | _timer.Start();
25 | }
26 |
27 | private void _timer_Tick(object sender, EventArgs e)
28 | {
29 | int val = Int32.Parse(txtTicks.Text);
30 | val++;
31 | txtTicks.Text = val.ToString();
32 | }
33 |
34 | private async void bttnRun_Case0(object sender, RoutedEventArgs e)
35 | {
36 | EnableButtons(false);
37 |
38 | var c = new Case0();
39 | Diag.PrintContext("BEFORE AWAIT");
40 | await c.Run();
41 | Diag.PrintContext("AFTER AWAIT");
42 |
43 | EnableButtons(true);
44 | }
45 |
46 | private async void bttnRun_Case1(object sender, RoutedEventArgs e)
47 | {
48 | EnableButtons(false);
49 |
50 | var c = new Case1();
51 | Diag.PrintContext("BEFORE AWAIT");
52 | await c.Run();
53 | Diag.PrintContext("AFTER AWAIT");
54 |
55 | EnableButtons(true);
56 | }
57 |
58 | private async void bttnRun_Case2(object sender, RoutedEventArgs e)
59 | {
60 | EnableButtons(false);
61 |
62 | var c = new Case2();
63 | Diag.PrintContext("BEFORE AWAIT");
64 | await c.Run();
65 | Diag.PrintContext("AFTER AWAIT");
66 |
67 | EnableButtons(true);
68 | }
69 |
70 |
71 | private async void bttnRun_Case3(object sender, RoutedEventArgs e)
72 | {
73 | EnableButtons(false);
74 |
75 | var c = new Case3();
76 | Diag.PrintContext("BEFORE AWAIT");
77 | await c.Run();
78 | Diag.PrintContext("AFTER AWAIT");
79 |
80 | EnableButtons(true);
81 | }
82 |
83 | private async void bttnRun_Case4(object sender, RoutedEventArgs e)
84 | {
85 | EnableButtons(false);
86 |
87 | var c = new Case4();
88 | Diag.PrintContext("BEFORE AWAIT");
89 | await c.Run();
90 | Diag.PrintContext("AFTER AWAIT");
91 |
92 | EnableButtons(true);
93 | }
94 |
95 | private void EnableButtons(bool enabled)
96 | {
97 | bttnRunCase0.IsEnabled = enabled;
98 | bttnRunCase1.IsEnabled = enabled;
99 | bttnRunCase2.IsEnabled = enabled;
100 | bttnRunCase3.IsEnabled = enabled;
101 | bttnRunCase4.IsEnabled = enabled;
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("YieldContextWPFSample")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("YieldContextWPFSample")]
15 | [assembly: AssemblyCopyright("Copyright © 2017")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ExtremeConfigAwaitWPFSample.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ExtremeConfigAwaitWPFSample.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ExtremeConfigAwaitWPFSample.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ConfigureAwaitBehavior/ExtremeConfigAwaitWPFSample/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Ben Williams
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # blog-examples
2 | This repo contains example code from posts on my blog https://blog.negativeeddy.com/
3 |
--------------------------------------------------------------------------------