具有性能计数器的Microsoft Owin Self Host在退出时挂起

时间:2016-06-07 14:04:39

标签: c# .net asp.net-web-api owin performancecounter

我有Owin自托管的web api应用程序(没有任何控制器)在Windows上有性能计数器,当我试图阻止它(停止我所有的内部服务,线程,处置web主机等)然后它挂起~10秒然后关闭。我的应用中没有留下任何线程。它等待约10秒然后退出。 如果我删除性能计数器逻辑或Web主机创建 - 应用程序正常关闭。

使用的Nuget包:

Microsoft.Owin.3.0.1
Microsoft.Owin.Host.HttpListener.3.0.1
Microsoft.Owin.Hosting.3.0.1
Newtonsoft.Json.6.0.8
Owin.1.0
System.Net.Http
System.Net.Http.Formatting (Microsoft.AspNet.WebApi.Client.5.2.3)
System.Web.Http (Microsoft.AspNet.WebApi.Core.5.2.3)
System.Web.Http.Owin (Microsoft.AspNet.WebApi.Owin.5.2.3)

.Net Framework使用:v4.5

Program.cs的

public class Program
{
    private static PerformanceCounter Counter;

    public static void Main(string[] args)
    {
        using (var webHost = WebApp.Start<Startup>("http://127.0.0.1:5000/"))
        {
            var process = Process.GetCurrentProcess();
            Counter = new PerformanceCounter("Process", "Thread Count", process.ProcessName, true);

            Console.WriteLine(Counter.NextValue());

            Console.ReadLine();

            Console.WriteLine("Exit1");
        }

        Console.WriteLine("Exit2"); // hangs after this
    }
}

Startup.cs

public class Startup
{
    public void Configuration(IAppBuilder appBuilder)
    {
        var config = new HttpConfiguration();

    // Web API routes
        config.MapHttpAttributeRoutes();
        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
    }
}

有什么想法? 提前谢谢。

0 个答案:

没有答案