gpt4 book ai didi

c# - 在 AppPool 循环后重新连接时,MVC5 卡在 MapSignalR 上

转载 作者:可可西里 更新时间:2023-11-01 07:55:23 25 4
gpt4 key购买 nike

我的 Startup.SignalR.cs 中有以下代码:

using Microsoft.AspNet.SignalR;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin
{
public partial class Startup
{
public void ConfigureSignalR(IAppBuilder app)
{
var Config = new HubConfiguration()
{
EnableDetailedErrors = false,
Resolver = new DefaultDependencyResolver()
};

#if DEBUG
Config.EnableDetailedErrors = true;
#endif
// Any connection or hub wire up and configuration should go here
app.MapSignalR();

GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(600);
}
}
}

在应用程序的初始加载期间,一切正常,但是当允许线程休眠时(保留约 10 分钟),AppPool 被回收并且线程卡在这条线上:

app.MapSignalR();

IDE 停留在绿色箭头和 This is the next statement to execute when this thread from the current function.。但是我不知道这个上下文中的 current function 是什么。

尝试检查任何局部变量会导致 无法计算表达式,因为 native 框架位于调用堆栈的顶部。 但是调用堆栈显示:Admin.dll!Admin.Startup。 ConfigureSignalR(Owin.IAppBuilder app) 第 25 行 作为顶部框架...

代码永远不会从此状态恢复,AppPool 必须通过重新启动调试 session 来完全重新启动。

有人对这种情况有任何解释吗?

附加信息:启用调试 => Windows => 并行堆栈后,我看到了更详细的堆栈跟踪:

[Managed to Native Transition]  
mscorlib.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string name, bool writable)
mscorlib.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string name)
System.dll!System.Diagnostics.PerformanceCounterLib.FindCustomCategory(string category, out System.Diagnostics.PerformanceCounterCategoryType categoryType)
System.dll!System.Diagnostics.PerformanceCounterLib.IsCustomCategory(string machine, string category)
System.dll!System.Diagnostics.PerformanceCounter.InitializeImpl()
System.dll!System.Diagnostics.PerformanceCounter.PerformanceCounter(string categoryName, string counterName, string instanceName, bool readOnly)
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.LoadCounter(string categoryName, string counterName, string instanceName, bool isReadOnly)
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.LoadCounter(string categoryName, string counterName, bool isReadOnly)
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.SetCounterProperties()
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.Initialize(string instanceName, System.Threading.CancellationToken hostShutdownToken)
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializePerformanceCounters(Microsoft.AspNet.SignalR.IDependencyResolver resolver, string instanceName, System.Threading.CancellationToken hostShutdownToken)
Microsoft.AspNet.SignalR.Core.dll!Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializeHost(Microsoft.AspNet.SignalR.IDependencyResolver resolver, string instanceName, System.Threading.CancellationToken hostShutdownToken)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.UseSignalRMiddleware<Microsoft.AspNet.SignalR.Owin.Middleware.HubDispatcherMiddleware>(Owin.IAppBuilder builder, object[] args)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.RunSignalR(Owin.IAppBuilder builder, Microsoft.AspNet.SignalR.HubConfiguration configuration)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.MapSignalR.AnonymousMethod__0(Owin.IAppBuilder subApp)
Microsoft.Owin.dll!Owin.MapExtensions.Map(Owin.IAppBuilder app, Microsoft.Owin.PathString pathMatch, System.Action<Owin.IAppBuilder> configuration)
Microsoft.Owin.dll!Owin.MapExtensions.Map(Owin.IAppBuilder app, string pathMatch, System.Action<Owin.IAppBuilder> configuration)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.MapSignalR(Owin.IAppBuilder builder, string path, Microsoft.AspNet.SignalR.HubConfiguration configuration)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.MapSignalR(Owin.IAppBuilder builder, Microsoft.AspNet.SignalR.HubConfiguration configuration)
Microsoft.AspNet.SignalR.Core.dll!Owin.OwinExtensions.MapSignalR(Owin.IAppBuilder builder)
Admin.dll!Admin.Startup.ConfigureSignalR(Owin.IAppBuilder app) Line 25

最佳答案

此博客文章的另一个修复方法: http://www.zpqrtbnk.net/posts/appdomains-threads-cultureinfos-and-paracetamol

app.SanitizeThreadCulture();

public static void SanitizeThreadCulture(this IAppBuilder app)
{
var currentCulture = CultureInfo.CurrentCulture;

// at the top of any culture should be the invariant culture,
// find it doing an .Equals comparison ensure that we will
// find it and not loop endlessly
var invariantCulture = currentCulture;
while (invariantCulture.Equals(CultureInfo.InvariantCulture) == false)
invariantCulture = invariantCulture.Parent;

if (ReferenceEquals(invariantCulture, CultureInfo.InvariantCulture))
return;

var thread = Thread.CurrentThread;
thread.CurrentCulture = CultureInfo.GetCultureInfo(thread.CurrentCulture.Name);
thread.CurrentUICulture = CultureInfo.GetCultureInfo(thread.CurrentUICulture.Name);
}

关于c# - 在 AppPool 循环后重新连接时,MVC5 卡在 MapSignalR 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31675939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com