public async Task ExecuteAsync(CancellationToken stoppingToken) { // Update real time values BigDataBoostDbInitializer.GenerateRunTimeData(Model.TagStatus.Good); await Task.Delay(1000, stoppingToken); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseCors(builder => builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod()); app.UseExceptionHandler( builder => { builder.Run( async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); var error = context.Features.Get <IExceptionHandlerFeature>(); if (error != null) { context.Response.AddApplicationError(error.Error.Message); await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false); } }); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); // Uncomment the following line to add a route for porting Web API 2 controllers. //routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); BigDataBoostDbInitializer.Initialize(app.ApplicationServices); valueTimer = new Timer(timer_Elapsed, null, 10000, 10000); //var wtoken = new CancellationTokenSource(); //var task = Task.Factory.StartNew(() => //{ // while (true) // { // wtoken.Token.ThrowIfCancellationRequested(); // BigDataBoostDbInitializer.GenerateRunTimeData((counter % modValue == 0? Model.TagStatus.Error : Model.TagStatus.Good)); // Thread.Sleep(useRealTimeValuesFrequency * 1000); // counter++; // if (counter > 100) // counter = 0; // } //}); }
private void timer_Elapsed(object state) { BigDataBoostDbInitializer.GenerateRunTimeData((counter % modValue == 0 ? Model.TagStatus.Error : Model.TagStatus.Good)); counter++; if (counter > 100) { counter = 0; } }