public async Task <bool> AnswerQuestionTimer(long questionid) { var userId = _securityContext.User.Id; var counter = 1; Task perdiodicTask = PeriodicTaskFactory.Start(() => { Console.WriteLine($"===========================Begin({counter})========================="); //_hubContext.Clients.User(userId.ToString()).SendAsync("ReceiveMessagePrivate", $"{counter}: {DateTime.Now}"); _hubContext.Clients.User(userId.ToString()).SendAsync("ReceiveMessagePrivate", JsonConvert.SerializeObject(new SocketObject() { Timestamp = GlobalSettings.CURRENT_DATETIME_AS_STRING, Object = new { Counter = counter }, Message = "Tick" })); counter++; }, intervalInMilliseconds: 1000, // fire every one seconds.. maxIterations: 20, periodicTaskCreationOptions: TaskCreationOptions.RunContinuationsAsynchronously); // for a total of 20 iterations... await perdiodicTask.ContinueWith(_ => { Console.WriteLine("===========================End========================="); _competitionQueryProcessor.AnswerQuestion(questionid, 0, userId); //_hubContext.Clients.User(userId.ToString()).SendAsync("ReceiveMessagePrivate", $"User did't answer, result is 0 {DateTime.Now}"); _hubContext.Clients.User(userId.ToString()).SendAsync("ReceiveMessagePrivate", JsonConvert.SerializeObject(new SocketObject() { Timestamp = GlobalSettings.CURRENT_DATETIME_AS_STRING, Object = new { Result = 0 }, Message = "User did't answer" })); }); return(true); }
public async Task AnswerQuestion(long questionId, long choiceId) { var x = _competitionQueryProcessor.AnswerQuestion(questionId, choiceId, int.Parse(Context.UserIdentifier)); await SendMessageToCaller("User Answered from websocket", new { Result = x }); }