using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; class Program { static void Main(string[] args) { int i = 5; Console.WriteLine("before: {0}", i); var thread = new myThread( (state) => { state.value += 1; } ); thread.Start( (obj) => { i = obj; }, () => i ); while (thread.IsAlive) ; Console.WriteLine("after: {0}", i); } class myThread { public delegate void ThreadStart(StateObject state); private Thread _thread; public myThread(ThreadStart start) { _thread = new Thread((obj) => { start.Invoke((StateObject)obj); }); } public void Start(StateObject obj) { _thread.Start(obj); } public void Start(Action f_set, Func f_get) { _thread.Start(new StateObject(f_set, f_get)); } public bool IsAlive { get { return _thread.IsAlive; } } public class StateObject { private Action _f_set; private Func _f_get; public StateObject(Action f_set, Func f_get) { _f_set = f_set; _f_get = f_get; } public T value { set { _f_set(value); } get { return _f_get(); } } } } }