private void TakeAction(Object obj) { ItemChangeState <T> parameter = obj as ItemChangeState <T>; if (parameter != null) { parameter.Item = OnTake(); _tableThread.AddOrUpdate(parameter.KeyThread, false, (i, b) => { return(false); }); } }
public async Task Add_AtThread_2(T item_1, T item_2) { ResultDouble <T> result = new ResultDouble <T>(); _countThread++; _tableThread.AddOrUpdate(_countThread, true, (i, b) => { return(true); }); Thread threadFirst = new Thread(new ParameterizedThreadStart(AddAction)); threadFirst.IsBackground = true; ItemChangeState <T> parameterFirst = new ItemChangeState <T>() { KeyThread = _countThread, Item = item_1 }; _countThread++; _tableThread.AddOrUpdate(_countThread, true, (i, b) => { return(true); }); Thread threadSecond = new Thread(new ParameterizedThreadStart(AddAction)); threadSecond.IsBackground = true; ItemChangeState <T> parameterSecond = new ItemChangeState <T>() { KeyThread = _countThread, Item = item_2 }; threadFirst.Start(parameterFirst); threadSecond.Start(parameterSecond); result.Value_1 = await Task <T> .Run( () => { while (_tableThread[parameterFirst.KeyThread]) { } return(parameterFirst.Item); } ); result.Value_2 = await Task.Run( () => { while (_tableThread[parameterSecond.KeyThread]) { } return(parameterSecond.Item); } ); }