public ActionResult About() { ViewBag.Message = "Your application description page."; log.Debug("Started"); var task = Task.Factory.StartNew(() => { IISNotifier notif = new IISNotifier(); notif.Started(); log.Debug("Task started"); Thread.Sleep(60000); log.Debug("Task ended"); notif.Finished(); }); log.Debug("Task waiting..."); task.Wait(); log.Debug("Task finished..."); return(View()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); WebApiConfig.Register(GlobalConfiguration.Configuration); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); log4net.Config.XmlConfigurator.Configure(); Notifier.Started(); }
//public static void DoWork(object parameters) //{ // var par = (ExecParameter)parameters; // UnicodeEncoding uniEncoding = new UnicodeEncoding(); // int maxCount = 60; // for (int i = 0; i < maxCount; i++) // { // string message = $", {i}"; // par.OutStream.Write(uniEncoding.GetBytes(message), 0, uniEncoding.GetBytes(message).Length); // log.Debug(i.ToString()); // Task.Delay(1000).Wait(); // } // log.Debug("Finish"); // par.Notif.Finished(); //} // http://localhost:12084/api/file public HttpResponseMessage Get() { //var man = ApplicationManager.GetApplicationManager(); //var notif = (IISNotifier)man.CreateObject(HostingEnvironment.ApplicationHost, typeof(IISNotifier)); //var notif = new IISNotifier(); //notif.Started(); //IISNotifier Notifier = new IISNotifier(); //Notifier.Started(); log.Debug("---------------------------------------------"); var notif = new IISNotifier(); notif.Started(); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new PushStreamContent((outputStream, httpContext, transportContext) => { log.Debug("PushStreamContent started"); //HostingEnvironment.QueueBackgroundWorkItem(token => //{ log.Debug("Task started"); UnicodeEncoding uniEncoding = new UnicodeEncoding(); int maxCount = 60; for (int i = 0; i < maxCount; i++) { string message = $", {i}"; outputStream.Write(uniEncoding.GetBytes(message), 0, uniEncoding.GetBytes(message).Length); log.Debug(i.ToString()); Thread.Sleep(1000); } log.Debug("Finish"); notif.Finished(); //}); }), }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); result.Content.Headers.ContentEncoding.Add("utf-8"); return(result); }
// http://localhost:12084/api/file public HttpResponseMessage Get() { //var man = ApplicationManager.GetApplicationManager(); //var notif = (IISNotifier)man.CreateObject(HostingEnvironment.ApplicationHost, typeof(IISNotifier)); //var notif = new IISNotifier(); //notif.Started(); //IISNotifier Notifier = new IISNotifier(); //Notifier.Started(); log.Debug("---------------------------------------------"); var notif = new IISNotifier(); notif.Started(); log.Debug("Task started"); int maxCount = 60; for (int i = 0; i < maxCount; i++) { string message = $", {i}"; //outputStream.Write(uniEncoding.GetBytes(message), 0, uniEncoding.GetBytes(message).Length); log.Debug(i.ToString()); Thread.Sleep(1000); } log.Debug("Finish"); notif.Finished(); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = null }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); result.Content.Headers.ContentEncoding.Add("utf-8"); return result; }