public void ReferencePassingTest() { var data = new DataBag(); ThreadingHelpers.ExecuteOnThreadPoolUnsafe( () => data.X++, 10); Assert.Equal(10, data.X); }
public void TimeoutCancellationTest() { var errorActionMock = new Mock <Action <Exception> >(); CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(200); ThreadingHelpers.ExecuteOnThreadPoolUnsafe( () => Thread.Sleep(100), 10, cts.Token, errorAction: errorActionMock.Object); errorActionMock.Verify(m => m(It.IsAny <OperationCanceledException>()), Times.Once); }
public void RunningOnDifferentThreadTest() { var mainThreadId = Thread.CurrentThread.ManagedThreadId; var testThreadId = 0; bool?testThreadIsFromPool = null; ThreadingHelpers.ExecuteOnThreadPoolUnsafe( () => { Thread.Sleep(100); testThreadId = Thread.CurrentThread.ManagedThreadId; testThreadIsFromPool = Thread.CurrentThread.IsThreadPoolThread; }, 1); Assert.NotEqual(0, testThreadId); Assert.NotEqual(mainThreadId, testThreadId); Assert.NotNull(testThreadIsFromPool); Assert.True(testThreadIsFromPool); }
public void ExecuteOnThreadPoolUnsafe() { ThreadingHelpers.ExecuteOnThreadPoolUnsafe(() => sha256.ComputeHash(data), 1); }