private void Bt_Run_Click(object sender, RoutedEventArgs e) { Console.Clear(); Status = "Start compile"; if (thread != null) { thread.Abort(); } string program = Tb_Code.Text; thread = new Thread(() => { Compiler c = new Compiler(program); string completed = ""; try { completed = c.Run(); } catch (Exception ex) { completed = ex.ToString(); MessageBox.Show(ex.ToString()); Status = "Error occured"; } RunCompleted?.Invoke(c, completed); }); thread.IsBackground = true; thread.Start(); }
private async Task <Speedtest> RunSpeedtest(DateTimeOffset timestamp) { await _semaphore.WaitAsync(); IsRunning = true; RunStarted?.Invoke(); var test = new Speedtest { Timestamp = timestamp }; try { var settings = await _client.GetSettingsAsync(); var server = settings.Servers .OrderBy(s => s.Distance) .FirstOrDefault(); test.ServerLatency = await _client.TestServerLatencyAsync(server); test.DownloadSpeed = await _client.TestDownloadSpeedAsync(server); test.UploadSpeed = await _client.TestUploadSpeedAsync(server); _logger.LogInformation($"Test ran successfully - Time: {timestamp}, Latency: {test.ServerLatency} ms, " + $"Download: {test.DownloadSpeed / 1000} Mbps, Upload: {test.UploadSpeed / 1000} Mbps"); using var scope = _services.CreateScope(); var context = scope.ServiceProvider.GetRequiredService <AppDbContext>(); context.Speedtests.Add(test); await context.SaveChangesAsync(); } finally { IsRunning = false; RunCompleted?.Invoke(test); _semaphore.Release(); } return(test); }
private async Task RunInternal(IProgress <ProgressReport> progress) { this.progress = progress; await Task.Run(() => { ItemWorker[] startDesignerItems = GetStartDesignerItems(); ItemWorker[] endDesignerItems = GetEndDesignerItems(); // Start starteritems foreach (ItemWorker item in startDesignerItems) { ExecuteDesignerItem(item); } while (true) { // Continously check if all items finished already List <ItemWorker> unfinishedItemWorkers = itemWorkers.Where(t => t.DesignerItem.State != ItemState.Stopped && t.DesignerItem.State != ItemState.Error && t.DesignerItem.State != ItemState.NotExecuted).ToList(); if (unfinishedItemWorkers.Count == 0) { if (RunCompleted != null) { RunCompleted.Invoke(this, new EventArgs()); } break; } // Check if a new item can be started List <ItemWorker> finishedItems = itemWorkers.Where(t => t.DesignerItem.State == ItemState.Stopped || t.DesignerItem.State == ItemState.Error || t.DesignerItem.State == ItemState.NotExecuted).ToList(); foreach (ItemWorker itemWorker in unfinishedItemWorkers.Where(t => t.DesignerItem.State == ItemState.Initialized)) { // Initialize bool newItemCanBeStarted = true; // If not all incoming connections to the item are from finished items, the item may not be started IEnumerable <ConnectionBase> incomingConnections = FlowHelper.GetIncomingConnections(itemWorker.DesignerItem.ID, connectionList); foreach (ConnectionBase connection in incomingConnections) { if (finishedItems.Where(t => t.DesignerItem.ID == connection.SourceID).Count() == 0) { newItemCanBeStarted = false; } } if (newItemCanBeStarted == true) { // Check if all incoming connection allow an execution bool allowExecution_PreviousErrorTest = FlowHelper.AllowExecution_OnPreviousErrorTest(itemWorker, this.itemWorkers, this.connectionList); bool allowExecution_PreviousItemNotSuccessfulOnErrorlineTest = FlowHelper.AllowExecution_PreviousStepNotSuccessfulOnErrorlineTest(itemWorker, this.itemWorkers, this.connectionList); if (allowExecution_PreviousErrorTest && allowExecution_PreviousItemNotSuccessfulOnErrorlineTest) { ExecuteDesignerItem(itemWorker); } else { DoNotExecuteDesignerItem(itemWorker); } } } System.Threading.Thread.Sleep(200); } this.runLog.EndTime = DateTime.Now; string serializedRunLog = ConfigurationSerializer.SerializeObject(runLog, new Type [] {}); ConfigurationFileHandler.SaveStringToFile("runLog.xml", this.runLog.RunLogPath, serializedRunLog); }); }
protected void InvokeRunCompleted() { RunCompleted?.Invoke(); }