Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
18
Task/Gotchas/C-sharp/gotchas.cs
Normal file
18
Task/Gotchas/C-sharp/gotchas.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
|
||||
// Methods that return values and don't modify the object
|
||||
|
||||
int[] arr = [1, 2, 3, 4, 5];
|
||||
arr.Reverse();
|
||||
Console.WriteLine(string.Join(", ", arr));
|
||||
|
||||
|
||||
// Tasks are not threads! There are not 50 threads here even though there are 50 tasks.
|
||||
// See https://blog.stephencleary.com/2013/11/there-is-no-thread.html
|
||||
|
||||
Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
|
||||
Task[] tasks = [.. Enumerable.Range(0, 50).Select(i => Task.Delay(1000))];
|
||||
Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
|
||||
Task.WaitAll(tasks);
|
||||
Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
|
||||
Loading…
Add table
Add a link
Reference in a new issue