服务的范例已在运行中

xswwsx1234567 2010-06-26 09:21:02
我在asp.net 中 用如下的代码 重启 iis 进程

ServiceController sc = new ServiceController("iisadmin");
sc.Start();

HttpRuntime.UnloadAppDomain();
Process p = new Process();
结果报错

服务的范例已在运行中
是怎么回事
...全文
529 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xswwsx1234567 2010-06-27
  • 打赏
  • 举报
回复
我把下面的这段代码 放在 page_load 事件中的最后

ServiceController sc = new ServiceController("iisadmin");
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped); //等待服务停止
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
}
else
{
sc.Start();
}

HttpRuntime.UnloadAppDomain();
Process p = new Process();
或是放到
控制台程序中

这样iis 不工作了,再次浏览网页就打不开了,得先停止iis ,再启动iis 才可以浏览,这是怎么回事

Nick黄 2010-06-26
  • 打赏
  • 举报
回复
学习了
wuyq11 2010-06-26
  • 打赏
  • 举报
回复
ServiceController sc = new ServiceController("aspnet_state");
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped); //等待服务停止
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
}
else
{
sc.Start();
}
  • 打赏
  • 举报
回复
if (sc.Status != ServiceControllerStatus.Running)
{
sc.Start();
}
else
{
sc.Stop();
while (sc.Status != ServiceControllerStatus.Stopped)
{
Thread.Sleep(1000);
}
sc.Start();
}
xswwsx1234567 2010-06-26
  • 打赏
  • 举报
回复
那上面代码该怎么改啊 ,我就是要重启iis 进程 啊 ,就是要先关闭 再开始啊
  • 打赏
  • 举报
回复
重启前先判断一下service的状态
zjtpiaoxue 2010-06-26
  • 打赏
  • 举报
回复
iis进程在你重启前没有关闭

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧