Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Created March 9, 2020 22:41
Show Gist options
  • Save samueleresca/3d0607be7945aa8ece9aced1d9ede8b4 to your computer and use it in GitHub Desktop.
Save samueleresca/3d0607be7945aa8ece9aced1d9ede8b4 to your computer and use it in GitHub Desktop.
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