public async override Task <OptimizerResult> Minimize(double[] parameters) { if (CancellationToken.IsCancellationRequested) { throw new TaskCanceledException(); } if (_minimize == null) { var assembly = await _cSharpCompiler.CreateAssembly(Code); _minimize = _cSharpCompiler.GetDelegate(assembly); } var cost = await _minimize(parameters); await Task.Run(() => { ActivityLogger.Add(Guid.NewGuid().ToString(), Keys, parameters, cost); //ActivityLogger.Add("Parameters:", parameters); //ActivityLogger.Add("Cost:", cost); //ActivityLogger.StateHasChanged(); }); return(new OptimizerResult(parameters, cost)); }
public async override Task <OptimizerResult> Minimize(double[] parameters) { if (CancellationToken.IsCancellationRequested) { throw new TaskCanceledException(); } if (_minimize == null) { var assembly = await _cSharpCompiler.CreateAssembly(Code); var worker = await _workerFactory.CreateAsync(); _backgroundService = await worker.CreateBackgroundServiceAsync <MinimizeFacade>(); _minimize = _cSharpCompiler.GetDelegate(assembly); } var cost = await _backgroundService.RunAsync(r => r.Minimize(_minimize, parameters)).Result; await Task.Run(() => { ActivityLogger.Add(Guid.NewGuid().ToString(), Keys, parameters, cost); //ActivityLogger.Add("Parameters:", parameters); //ActivityLogger.Add("Cost:", cost); //ActivityLogger.StateHasChanged(); }); return(new OptimizerResult(parameters, cost)); }