/// <inheritdoc/> protected override async Task <bool> ProtectedHandleAsync(ResetTaskStatusCommand request, CancellationToken cancellationToken) { await ResetAsync(cancellationToken); var entities = Context.TaskRepository.GetQuery(e => e.Status == (int)Domain.Enums.TaskStatus.Queued) .OrderBy(e => e.CreatedDate) .ThenBy(e => e.Id); var iteration = 0; while (true) { var entitiesBatch = entities.Skip(iteration * batchSize).Take(batchSize).ToList(); if (entitiesBatch.Count <= 0) { break; } else { foreach (var entity in entitiesBatch) { var result = TaskModel.Create(entity, serializer); } iteration++; } } return(true); }
public async Task TestWaiting() { var giveResult = new SemaphoreSlim(0); var gotResult = new SemaphoreSlim(0); Func <CancellationToken, ValueTask <int> > factory = async ct => { await giveResult.WaitAsync(ct).ConfigureAwait(false); return(5); }; void OnPropertyChanged(object sender, PropertyChangedEventArgs args) { gotResult.Release(); } var tpc = TaskModel.Create(factory); Assert.False(tpc.HasValue); tpc.PropertyChanged += OnPropertyChanged; Assert.False(tpc.HasValue); giveResult.Release(); if (!await gotResult.WaitAsync(5_000)) { throw new Exception("Deadlock"); } Assert.True(tpc.HasValue); Assert.Equal(5, tpc.Value); }
public ActionResult Create(FormCollection form) { Task task = new Task(); task.Title = form["Title"]; task.Description = form["Description"]; task.Status = 1; using (TaskModel model = new TaskModel()) { model.Create(task); return(RedirectToAction("Index")); } }