December 2019
Intermediate to advanced
598 pages
12h 21m
English
An easy mistake to make is to mix asynchronous code with synchronous code. In fact, we have made this mistake in our PostAnswer action method because the method is synchronous but the call to the SignalR hub is asynchronous:
[HttpPost("answer")]public ActionResult<AnswerGetResponse> PostAnswer(AnswerPostRequest answerPostRequest){ ... _questionHubContext.Clients.Group( $"Question-{answerPostRequest.QuestionId.Value}") .SendAsync( "ReceiveQuestion", _dataRepository.GetQuestion(answerPostRequest.QuestionId.Value) ); return savedAnswer;}
The code functions correctly but is suboptimal because not only is the thread that handles the request blocked from handling other requests, but we also have all of ...
Read now
Unlock full access