Created
March 9, 2020 22:41
-
-
Save samueleresca/3d0607be7945aa8ece9aced1d9ede8b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using Xunit; | |
using Xunit.Abstractions; | |
namespace Blog.Threading | |
{ | |
public class ThreadInitialization | |
{ | |
private readonly ITestOutputHelper _testOutputHelper; | |
public ThreadInitialization(ITestOutputHelper testOutputHelper) | |
{ | |
_testOutputHelper = testOutputHelper; | |
} | |
void Secondary() | |
{ | |
for (int i = 0; i < 1000; i++) _testOutputHelper.WriteLine($"Ping from {nameof(Secondary)}"); | |
} | |
[Fact] | |
void Thread_initialization_Thread_Start() | |
{ | |
var t = new Thread(Secondary); | |
t.Start(); | |
for (int i = 0; i < 1000; i++) _testOutputHelper.WriteLine("Ping from Mai!"); | |
} | |
[Fact] | |
void Thread_initialization_Thread_Pool() | |
{ | |
ThreadPool.QueueUserWorkItem(_ => Secondary()); | |
for (int i = 0; i < 1000; i++) _testOutputHelper.WriteLine("Ping from Main"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment