0
我們正在運行一個Windows控制檯應用程序,它通過SignalR背板將SignalR消息發送到多個瀏覽器。我們通過舉辦使用OWN.WebApp一個SignalR服務器這樣做:在WebApp中捕獲異常?
public class SignalRWebApp : IDisposable
{
public readonly string signalRUrl;
private IDisposable webApp;
public SignalRWebApp()
{
this.signalRUrl = String.Format("http://localhost:{0}", getFreePort());
this.webApp = null;
}
private static int getFreePort()
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint) listener.LocalEndpoint).Port;
listener.Stop();
return port;
}
public bool started { get { return this.webApp != null; } }
public void start(string signalRBackplaneConnectionString)
{
if (this.webApp != null)
return;
Action<IAppBuilder> startAction = app =>
{
app.UseCors(CorsOptions.AllowAll);
GlobalHost.DependencyResolver.UseSqlServer(signalRBackplaneConnectionString);
app.MapSignalR();
};
this.webApp = WebApp.Start(this.signalRUrl, startAction);
}
#region IDisposable
public void Dispose()
{
this.dispose(true);
GC.SuppressFinalize(this);
}
~SignalRWebApp()
{
this.dispose(false);
}
private bool alreadyDisposed;
protected virtual void dispose(bool disposing)
{
if (!this.alreadyDisposed)
{
if (disposing)
{
// dispose managed objects
if (this.webApp != null)
{
this.webApp.Dispose();
this.webApp = null;
}
}
// free unmanaged objects
// set large fields to null.
this.alreadyDisposed = true;
}
}
#endregion
}
基本上,我們創建了一個SignalRWebApp對象,然後調用start(),連接字符串傳遞到SQLServer的背板數據庫。 OWIN在後臺線程中啓動一個網站,我們的代碼通過signalRUrl(這是一個帶有動態分配端口號的本地主機)與它進行通信。
我的問題:這是在我們的開發和QA環境中工作,但在我們的演示環境中,它沒有解釋就崩潰了。
我正在經歷並試圖確保我們至少捕獲並記錄可能發生的任何異常。這就是事情 - 我看不到如何捕捉和記錄OWIN WebApp可能拋出的任何異常。
任何想法?
您是否檢查過Windows事件日誌?如果你沒有發現異常,通常會出現在那裏 – thab