One of possible methods to return a value from a Thread is to use a context class as a parameter object. It can be used to pass parameters and retrieve the result as well.
If on the other hand you could use a BackgroundWorker class, it has already a dedicated Result object - that works the same way. But BackgroundWorker cannot be used for some purposes (for instance, it doesn't support STA Apartment State).
Keep in mind that you shouldn't read from ctx.Result until the thread is finished (i.e. t.IsAlive == false).
void runThread() { ThreadContext ctx = new ThreadContext(); ctx.Value = 8; Thread t = new Thread(new ParameterizedThreadStart(MyThread)); //t.SetApartmentState(ApartmentState.STA); // required for some purposes t.Start(ctx); // ... t.Join(); Console.WriteLine(ctx.Result); } private static void MyThread(object threadParam) { ThreadContext context = (ThreadContext)threadParam; context.Result = context.Value * 4; // compute result } class ThreadContext { public int Value { get; set; } public int Result { get; set; } }
volatile?