diff --git a/MultiThreadingStudy.xUnitTest/ThreadTest.cs b/MultiThreadingStudy.xUnitTest/ThreadTest.cs new file mode 100644 index 0000000..2d786fa --- /dev/null +++ b/MultiThreadingStudy.xUnitTest/ThreadTest.cs @@ -0,0 +1,60 @@ +using Xunit.Abstractions; + +namespace MultiThreadingStudy.xUnitTest +{ + public class ThreadTest:IDisposable + { + private readonly ITestOutputHelper _output; + + public ThreadTest(ITestOutputHelper testOutput) + { + _output = testOutput; + } + + /// <summary> + /// ���Է����������߳�Ϊ��̨�߳� + /// ���ۣ��ڲ��Է��������������߳�(��ʹ���ó�ǰ̨�߳�)��Ĭ������£�������ֹ��Ԫ���Է�����ִ�н����� + /// ���Է����ܿ����������������߳̽������У�������߳�û��ִ��������Ų��Է����߳̽����������� + /// </summary> + [Fact] + public void TestRunThread_Test() + { + _output.WriteLine($"���߳�Id={Thread.CurrentThread.ManagedThreadId}, �Ƿ��̨�߳�={Thread.CurrentThread.IsBackground}"); + + //���ԣ����Ե������߳�Ϊ��̨�߳� + Assert.True( Thread.CurrentThread.IsBackground); + } + + /// <summary> + /// + /// </summary> + [Fact] + public void Test1() + { + _output.WriteLine($"���߳�Id={Thread.CurrentThread.ManagedThreadId}, �Ƿ��̨�߳�={Thread.CurrentThread.IsBackground}"); + + + Thread t = new Thread(() => + { + _output.WriteLine($"���߳�Id={Thread.CurrentThread.ManagedThreadId}, ���߳�����={Thread.CurrentThread.Name}"); + + _output.WriteLine($"{Thread.CurrentThread.Name} ���̣߳���ʼ����"); + Thread.Sleep(100); + _output.WriteLine($"{Thread.CurrentThread.Name} ���̴߳������л��ѣ�ִ�н�����"); + }) + { + Name = "FirstThread", + Priority = ThreadPriority.Normal, + IsBackground = false, + }; + + t.Start(); + t.Join(); + } + + public void Dispose() + { + + } + } +} \ No newline at end of file diff --git a/MultiThreadingStudy.xUnitTest/UnitTest1.cs b/MultiThreadingStudy.xUnitTest/UnitTest1.cs deleted file mode 100644 index 22d3b78..0000000 --- a/MultiThreadingStudy.xUnitTest/UnitTest1.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MultiThreadingStudy.xUnitTest -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } -} \ No newline at end of file diff --git a/MultiThreadingStudy.xUnitTest/UseXunit.cs b/MultiThreadingStudy.xUnitTest/UseXunit.cs new file mode 100644 index 0000000..79b14b9 --- /dev/null +++ b/MultiThreadingStudy.xUnitTest/UseXunit.cs @@ -0,0 +1,25 @@ +using Xunit.Abstractions; + +namespace MultiThreadingStudy.xUnitTest +{ + public class UseXunit:IDisposable + { + private readonly ITestOutputHelper _output; + + public UseXunit(ITestOutputHelper testOutput) + { + _output = testOutput; + } + + [Fact] + public void Test1() + { + _output.WriteLine("ʹ�� xUnit ��־"); + } + + public void Dispose() + { + + } + } +} \ No newline at end of file diff --git a/MultiThreadingStudy.xUnitTest/Usings.cs b/MultiThreadingStudy.xUnitTest/Usings.cs index 8c927eb..2dfbf26 100644 --- a/MultiThreadingStudy.xUnitTest/Usings.cs +++ b/MultiThreadingStudy.xUnitTest/Usings.cs @@ -1 +1,5 @@ -global using Xunit; \ No newline at end of file +global using Xunit; + +global using System.Threading; +global using System.Threading.Channels; +global using System.Threading.Tasks; \ No newline at end of file