private void SendMessage() { string message = null; while (true) { if (_recievedmessage) { string lastWord = _receivedWords.Last(); if (lastWord.Length > 1) { message = _wordProvider.GetWord(lastWord.Substring(lastWord.Length - 1, 1), _receivedWords, _words); if (message != null) { message = string.Concat(_threadName, message); byte[] data = Encoding.Unicode.GetBytes(message); _stream.Write(data, 0, data.Length); _recievedmessage = false; } else { NewMessage(this, new NewMessageEventArgs(string.Concat(_threadName, "Sorry, i lose"))); message = string.Concat(_threadName, "exit1"); byte[] data = Encoding.Unicode.GetBytes(message); _stream.Write(data, 0, data.Length); _recievedmessage = false; _receiveThread.Abort(); } } } Thread.Sleep(5000); } }
public async Task <WordUpdateResult> UpdateWord(WordUpdate model) { await validator.ValidateUpdateModel(model); var toUpdate = await context.Words.SingleOrDefaultAsync(x => x.Id == model.Id); if (toUpdate == null) { throw new ArgumentException($"Can't find word with id {model.Id}"); } toUpdate = mapper.MapWord(toUpdate, model); await context.SaveChangesAsync(); var wordModel = await wordProvider.GetWord(model.Id); return(new WordUpdateResult() { Word = wordModel }); }