![](/img/trans.png)
[英]Reload web.config after updating connectionstring programmatically in C#
[英]IIS CPU goes bezerk after updating web.config in a C# application with a Singleton with a thread
我有一个Web应用程序执行以下操作:
单击按钮以实例化单例,从而创建一个Thread。 该Thread持续运行一些HTTP请求来收集一些数据。 您可以单击在线程上调用Abort()方法的停止按钮,并且应用程序停止发出HTTP请求。 当我手动启动/停止它时,一切正常。
当我“触摸”web.config时,我的问题就出现了。 CPU(w3wp.exe进程)激增,网站停止响应。 有人知道为什么会这样吗? 不应该更新web.config重置一切?
示例代码如下:
private static MyProcessor mp = null;
private Thread theThread = null;
private string status = STOP;
public static string STOP = "Stopped";
public static string START = "Started";
private MyProcessor()
{}
public static MyProcessor getInstance()
{
if (mp == null)
{
mp = new MyProcessor();
}
return mp;
}
public void Start()
{
if (this.status == START)
return;
this.theThread = new Thread(new ThreadStart(this.StartThread));
this.theThread.Start();
this.status = START;
}
public void Stop()
{
if (this.theThread != null)
this.theThread.Abort();
this.status = STOP;
}
private void StartThread()
{
do
{
try
{
//do some work with HTTP requests
Thread.Sleep(1000 * 2);
}
catch (Exception e)
{
//retry - work forever
this.StartThread();
}
} while (this.status == START);
}
我怀疑这是问题所在:
private void StartThread()
{
do
{
try
{
//do some work with HTTP requests
Thread.Sleep(1000 * 2);
}
catch (Exception e)
{
//The recursive call here is suspect
//at the very least find a way to prevent infinite recursion
//--or rethink this strategy
this.StartThread();
}
} while (this.status == START);
}
当您的应用程序域重置时,您将获得一个ThreadAbort异常,该异常将在此处捕获并触发递归调用,这将触发另一个异常,以及另一个递归调用。 它一直是乌龟!
是的,在web .config中进行任何更改都会重置应用程序,并且asp.net会重新构建应用程序。
对于Bin和App_Code文件夹下的文件等其他文件也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.