Skip to content

Commit

Permalink
Update to net6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jerviscui committed May 31, 2024
1 parent 884e6dc commit 004b39c
Show file tree
Hide file tree
Showing 64 changed files with 295 additions and 192 deletions.
2 changes: 1 addition & 1 deletion src/7/FixedTest/FixedTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/7/RefTest/RefTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/7/SpanTest/SpanTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/7/StackallocTest/StackallocTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/7/ValueTaskTest/ValueTaskTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/7/ValueTupleTest/ValueTupleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/8/AsyncEnumerableTest/AsyncEnumerableTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/8/GenericStructTest/GenericStructTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/8/MemoryTest/MemoryTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/8/RangeIndexTest/RangeIndexTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/8/SwitchExpressionTest/SwitchExpressionTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/9/LocalFunctionTest/LocalFunctionTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
6 changes: 3 additions & 3 deletions src/9/LocalFunctionTest/LocalFunctionWithTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class LocalFunctionWithTask
{
public static async Task Test()
{
Console.WriteLine($"#{Thread.CurrentThread.ManagedThreadId.ToString()} Test");
Console.WriteLine($"#{Environment.CurrentManagedThreadId.ToString()} Test");
var t = NoLocalFunc(6);
//var t = LocalFunc(6); //LocalFunc() 在这里抛出异常
Console.WriteLine("Got the task");

Console.WriteLine($"#{Thread.CurrentThread.ManagedThreadId.ToString()} Test");
Console.WriteLine($"#{Environment.CurrentManagedThreadId.ToString()} Test");
var result = await t; //NoLocalFunc() 在这里抛出异常
Console.WriteLine($"#{Thread.CurrentThread.ManagedThreadId.ToString()} The returned value is {result:N0}");
Console.WriteLine($"#{Environment.CurrentManagedThreadId.ToString()} The returned value is {result:N0}");
}

private static async Task<int> NoLocalFunc(int delayInSeconds)
Expand Down
2 changes: 2 additions & 0 deletions src/9/NullableEnableTest/DictionaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace NullableEnableTest
{
public class Item
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public string Name { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}

public class DictionaryTest
Expand Down
2 changes: 1 addition & 1 deletion src/9/NullableEnableTest/NullableEnableTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions src/9/NullableEnableTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ private static void Main(string[] args)
{
//在全局开启了 <Nullable>enable</Nullable>

#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
A a = A.GetOrDefault(false); //CS8600 将 null 文本或可能的 null 值转换为不可为 null 类型。
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
A? a1 = A.GetOrDefault(false);

#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
A a2 = A.GetOrDefault(true);
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
A a3 = A.GetOrDefault(true)!; //明确不会返回 null 时,可以在结尾加 ! 阻止 CS8600 警告

//Console.WriteLine("Hello World!");
Expand All @@ -19,7 +23,9 @@ public class A
{
//CS8618 在退出构造函数时,不可为 null 的 属性“Name”必须包含非 null 值。
//请考虑将 属性 声明为可以为 null。
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private A()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
//Name = string.Empty;
}
Expand Down
2 changes: 1 addition & 1 deletion src/9/RecordTest/RecordTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/9/SystemTextJson/SystemTextJsonTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>SystemTextJsonTest</AssemblyName>
</PropertyGroup>

Expand Down
26 changes: 13 additions & 13 deletions src/9/TaskGuidanceTest/ChildTaskTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public static void Test()
public static async Task AttachedChildTask()
{
//1
Console.WriteLine($"AttachedChildTask {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"AttachedChildTask {Environment.CurrentManagedThreadId.ToString()}");

await Task.Factory.StartNew(() =>
{
Console.WriteLine($"task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"task {Environment.CurrentManagedThreadId.ToString()}");
for (int ctr = 0; ctr < 10; ctr++)
{
Expand All @@ -31,23 +31,23 @@ await Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
Console.WriteLine(
$"Attached child #{x} completed. {Thread.CurrentThread.ManagedThreadId.ToString()}");
$"Attached child #{x} completed. {Environment.CurrentManagedThreadId.ToString()}");
}, taskNo, TaskCreationOptions.AttachedToParent);
}
});

//wait for all Attached Children
Console.WriteLine($"Completed {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"Completed {Environment.CurrentManagedThreadId.ToString()}");
}

public static async Task DetachedChildTask()
{
//1
Console.WriteLine($"DetachedChildTask {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"DetachedChildTask {Environment.CurrentManagedThreadId.ToString()}");

await Task.Factory.StartNew(() =>
{
Console.WriteLine($"task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"task {Environment.CurrentManagedThreadId.ToString()}");
for (int ctr = 0; ctr < 10; ctr++)
{
Expand All @@ -56,12 +56,12 @@ await Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
Console.WriteLine(
$"Detached child #{x} completed. {Thread.CurrentThread.ManagedThreadId.ToString()}");
$"Detached child #{x} completed. {Environment.CurrentManagedThreadId.ToString()}");
}, taskNo);
}
});

Console.WriteLine($"Completed {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"Completed {Environment.CurrentManagedThreadId.ToString()}");

//wait for all Detached Children
await Task.Delay(1000 * 5);
Expand All @@ -71,28 +71,28 @@ public static async Task AttachedChildTaskAndContinueTest()
{
//1
Console.WriteLine(
$"DirectReturnAndContinue_GetContextTest {Thread.CurrentThread.ManagedThreadId.ToString()}");
$"DirectReturnAndContinue_GetContextTest {Environment.CurrentManagedThreadId.ToString()}");

await Task.Factory.StartNew(() =>
{
//4
Console.WriteLine($"parent task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"parent task {Environment.CurrentManagedThreadId.ToString()}");
Task.Factory.StartNew(() =>
{
//5
Console.WriteLine($"attached child {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"attached child {Environment.CurrentManagedThreadId.ToString()}");
}, TaskCreationOptions.AttachedToParent);
}).ContinueWith(_ =>
{
//5
Console.WriteLine($"continue task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"continue task {Environment.CurrentManagedThreadId.ToString()}");
Console.WriteLine(SynchronizationContext.Current?.GetType().Name ?? "null");
}).ConfigureAwait(false);

//5
Console.WriteLine(SynchronizationContext.Current?.GetType().Name ?? "null");
Console.WriteLine($"Completed {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"Completed {Environment.CurrentManagedThreadId.ToString()}");
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/9/TaskGuidanceTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public static async Task SimpleTask()
public static async Task SimpleTask2()
{
//1
Console.WriteLine($"SimpleTask2 {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"SimpleTask2 {Environment.CurrentManagedThreadId.ToString()}");
await Task.Factory.StartNew(() =>
{
Thread.Sleep(1000 * 10);
//5
Console.WriteLine($"task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"task {Environment.CurrentManagedThreadId.ToString()}");
}, TaskCreationOptions.LongRunning);
var s = new StackTrace().GetFrames();
foreach (var stackFrame in s)
Expand All @@ -53,7 +53,7 @@ await Task.Factory.StartNew(() =>
Console.WriteLine($"{m.Module,-28} {m.DeclaringType,-103} {m.Name}");
}
//5
Console.WriteLine($"Completed {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"Completed {Environment.CurrentManagedThreadId.ToString()}");
//调用堆栈输出
//TaskGuidanceTest.dll TaskGuidanceTest.Program+TaskTest+<SimpleTask2>d__2 MoveNext
//System.Private.CoreLib.dll System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[TResult,TStateMachine] ExecutionContextCallback
Expand All @@ -77,17 +77,17 @@ await Task.Factory.StartNew(() =>
public static async Task ContinuationTask()
{
//1
Console.WriteLine($"ChildTask {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"ChildTask {Environment.CurrentManagedThreadId.ToString()}");
await Task.Factory.StartNew(() =>
{
Thread.Sleep(1000 * 1);
//4
Console.WriteLine($"task {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"task {Environment.CurrentManagedThreadId.ToString()}");
}).ContinueWith(task =>
{
//child task
//5
Console.WriteLine($"child {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"child {Environment.CurrentManagedThreadId.ToString()}");
var s = new StackTrace().GetFrames();
foreach (var stackFrame in s)
Expand All @@ -98,7 +98,7 @@ await Task.Factory.StartNew(() =>
}, TaskContinuationOptions.AttachedToParent);

//5
Console.WriteLine($"Completed {Thread.CurrentThread.ManagedThreadId.ToString()}");
Console.WriteLine($"Completed {Environment.CurrentManagedThreadId.ToString()}");

//TaskGuidanceTest.dll TaskGuidanceTest.Program+ChildTaskTest+<>c <ChildTask>b__1_1
//System.Private.CoreLib.dll System.Threading.Tasks.ContinuationTaskFromTask InnerInvoke
Expand Down
Loading

0 comments on commit 004b39c

Please sign in to comment.