public void Thread_Id_Provider_Same_Thread_Test() { var provider = new ThreadIdProvider(); int id1 = provider.GetThreadId(); int id2 = provider.GetThreadId(); Assert.IsTrue(id1 == id2); }
public void Thread_Id_Provider_Same_Thread_Dif_Instance() { var provider1 = new ThreadIdProvider(); var provider2 = new ThreadIdProvider(); var id1 = provider1.GetThreadId(); var id2 = provider2.GetThreadId(); Assert.IsTrue(id1 == id2); }
private int GetThreadIdFromAnotherThread(ThreadIdProvider provider) { int id = 0; Thread thread = new Thread(delegate() { //Do somthing and set your value id = provider.GetThreadId(); }); thread.Start(); while (thread.IsAlive) { Thread.Sleep(1); } return(id); }