Skip to content

Commit 4a0013f

Browse files
Merge pull request #130 from ProfessionalCSharp/126-synchronization-context
126 synchronization context
2 parents e986153 + 0335211 commit 4a0013f

21 files changed

+524
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.32804.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp.csproj", "{61A81C0C-8869-444F-9C90-CD10351604F6}"
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+
{61A81C0C-8869-444F-9C90-CD10351604F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{61A81C0C-8869-444F-9C90-CD10351604F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{61A81C0C-8869-444F-9C90-CD10351604F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{61A81C0C-8869-444F-9C90-CD10351604F6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {4DAAA480-BF32-46CE-A2D8-2BFA335B8E51}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ShowThreadAndTask("Started application");
2+
await SampleAsync().ConfigureAwait(true);
3+
4+
ShowThreadAndTask("Top level statements after calling SampleAsync");
5+
6+
SynchronizationContext? context = SynchronizationContext.Current;
7+
if (context == null)
8+
{
9+
Console.WriteLine("No synchronization context with console applications");
10+
}
11+
12+
Task SampleAsync()
13+
{
14+
return Task.Run(() =>
15+
{
16+
ShowThreadAndTask("Started AsyncMethod");
17+
});
18+
}
19+
20+
void ShowThreadAndTask(string title)
21+
{
22+
Console.WriteLine(title);
23+
string taskMessage = Task.CurrentId == null ? "no task" : $"in the task {Task.CurrentId}";
24+
Console.WriteLine($"running in thread {Environment.CurrentManagedThreadId} and {taskMessage}");
25+
Console.WriteLine();
26+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.32804.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{06CF9477-F3EE-4A86-BC47-73630AF59D0D}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsApp", "WindowsApp\WindowsApp.csproj", "{04E56059-085E-49AF-9B95-EBC400FE8EA7}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|arm64 = Debug|arm64
14+
Debug|x64 = Debug|x64
15+
Debug|x86 = Debug|x86
16+
Release|Any CPU = Release|Any CPU
17+
Release|arm64 = Release|arm64
18+
Release|x64 = Release|x64
19+
Release|x86 = Release|x86
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|arm64.ActiveCfg = Debug|Any CPU
25+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|arm64.Build.0 = Debug|Any CPU
26+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|x64.ActiveCfg = Debug|Any CPU
27+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|x64.Build.0 = Debug|Any CPU
28+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|x86.ActiveCfg = Debug|Any CPU
29+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Debug|x86.Build.0 = Debug|Any CPU
30+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|arm64.ActiveCfg = Release|Any CPU
33+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|arm64.Build.0 = Release|Any CPU
34+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|x64.ActiveCfg = Release|Any CPU
35+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|x64.Build.0 = Release|Any CPU
36+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|x86.ActiveCfg = Release|Any CPU
37+
{06CF9477-F3EE-4A86-BC47-73630AF59D0D}.Release|x86.Build.0 = Release|Any CPU
38+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|Any CPU.ActiveCfg = Debug|x64
39+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|Any CPU.Build.0 = Debug|x64
40+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|Any CPU.Deploy.0 = Debug|x64
41+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|arm64.ActiveCfg = Debug|arm64
42+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|arm64.Build.0 = Debug|arm64
43+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|arm64.Deploy.0 = Debug|arm64
44+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x64.ActiveCfg = Debug|x64
45+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x64.Build.0 = Debug|x64
46+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x64.Deploy.0 = Debug|x64
47+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x86.ActiveCfg = Debug|x86
48+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x86.Build.0 = Debug|x86
49+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Debug|x86.Deploy.0 = Debug|x86
50+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|Any CPU.ActiveCfg = Release|x64
51+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|Any CPU.Build.0 = Release|x64
52+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|Any CPU.Deploy.0 = Release|x64
53+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|arm64.ActiveCfg = Release|arm64
54+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|arm64.Build.0 = Release|arm64
55+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|arm64.Deploy.0 = Release|arm64
56+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x64.ActiveCfg = Release|x64
57+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x64.Build.0 = Release|x64
58+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x64.Deploy.0 = Release|x64
59+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x86.ActiveCfg = Release|x86
60+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x86.Build.0 = Release|x86
61+
{04E56059-085E-49AF-9B95-EBC400FE8EA7}.Release|x86.Deploy.0 = Release|x86
62+
EndGlobalSection
63+
GlobalSection(SolutionProperties) = preSolution
64+
HideSolutionNode = FALSE
65+
EndGlobalSection
66+
GlobalSection(ExtensibilityGlobals) = postSolution
67+
SolutionGuid = {1E203E45-C943-46DD-BEB3-2C11C9F27DD2}
68+
EndGlobalSection
69+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Application
2+
x:Class="WindowsApp.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:WindowsApp">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
10+
<!-- Other merged dictionaries here -->
11+
</ResourceDictionary.MergedDictionaries>
12+
<!-- Other app resources here -->
13+
</ResourceDictionary>
14+
</Application.Resources>
15+
</Application>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.UI.Xaml;
2+
using Windows.ApplicationModel.Core;
3+
4+
namespace WindowsApp;
5+
6+
public partial class App : Application
7+
{
8+
public App()
9+
{
10+
InitializeComponent();
11+
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
12+
{
13+
14+
};
15+
CoreApplication.UnhandledErrorDetected += (sender, e) =>
16+
{
17+
18+
};
19+
UnhandledException += (sender, e) =>
20+
{
21+
22+
};
23+
}
24+
25+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
26+
{
27+
_window = new MainWindow();
28+
_window.Activate();
29+
}
30+
31+
private Window? _window;
32+
}
432 Bytes
Loading
5.25 KB
Loading
1.71 KB
Loading
637 Bytes
Loading

0 commit comments

Comments
 (0)