首页 新闻 会员 周边

web服务的启动时间

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-10-10 10:54

我自己新添加的一个服务为啥只能启动几秒就自动停止啦

待重逢的主页 待重逢 | 初学一级 | 园豆:10
提问于:2012-09-29 09:41
< >
分享
所有回答(2)
1

有错误还是你设置你的timer控件是一次运行的?

chenping2008 | 园豆:9836 (大侠五级) | 2012-09-29 09:45

错误倒是没有,应为我在控制台应用程序里面已经测试过啦,我没有用timer控件,这是我的代码

    bool Running;     

    protected override void OnStart(string[] args)

        {             // TODO: 在此处添加代码以启动服务。

            Running = true;       

      new Thread(DoWork).Start();

            PY.General.IO.AppendLog(System.AppDomain.CurrentDomain.BaseDirectory + "startservice.txt" , "开始服务");   

      }       

  protected override void OnStop()     

    {             // TODO: 在此处添加代码以执行停止服务所需的关闭操作。             PY.General.IO.AppendLog(System.AppDomain.CurrentDomain.BaseDirectory + "stopservice.txt", "停止服务");      

       Running = false;     

    }      

   private void DoWork()   

      {            

while (Running)       

      {               

  Thread thd = new Thread(new ThreadStart(receive));   

              thd.Start();       

          Thread thd2 = new Thread(new ThreadStart(sendmail));    

             thd2.Start();              

   Thread.Sleep(10 * 60 * 1000);        

     }       

  }

支持(0) 反对(0) 待重逢 | 园豆:10 (初学一级) | 2012-09-29 10:03

@待重逢: 你的代码就做一次,如果想要一直可以做下去,请用timer控件定时的执行你的程序

支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-09-29 10:19

@chenping2008:  我不会写啊!你可以帮我写出来吗?写了啊

支持(0) 反对(0) 待重逢 | 园豆:10 (初学一级) | 2012-09-29 10:28

@chenping2008: 我的服务为啥不能直接运行啊!错误是:无法从命令行或调试器启动服务,必须首先安装windows服务(使用installutil.exe),然后用serverexplorer,windows服务管理工具或没netstart命令启动它。这是什么情况啊,

支持(0) 反对(0) 待重逢 | 园豆:10 (初学一级) | 2012-09-29 10:48

@待重逢: 肯定要先安装window服务,才可以运行的

http://blog.csdn.net/xxj_jing/article/details/7542654

支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-09-29 13:37
0

你得安装到windows service后,就能运行了。不支持直接运行的哦,亲。

Ethan轻叹 | 园豆:996 (小虾三级) | 2012-09-29 11:41

我的服务为啥只能启动几秒就停止啦啊,这是我写的代码

 bool Running;    

    protected override void OnStart(string[] args)

        {             // TODO: 在此处添加代码以启动服务。

            Running = true;      

      new Thread(DoWork).Start();

            PY.General.IO.AppendLog(System.AppDomain.CurrentDomain.BaseDirectory + "startservice.txt" , "开始服务");  

      }      

  protected override void OnStop()    

    {             // TODO: 在此处添加代码以执行停止服务所需的关闭操作。             PY.General.IO.AppendLog(System.AppDomain.CurrentDomain.BaseDirectory + "stopservice.txt", "停止服务");     

       Running = false;    

    }     

   private void DoWork()  

      {           

while (Running)      

      {              

  Thread thd = new Thread(new ThreadStart(receive));  

              thd.Start();      

          Thread thd2 = new Thread(new ThreadStart(sendmail));   

             thd2.Start();             

   Thread.Sleep(10 * 60 * 1000);       

     }      

  }

支持(0) 反对(0) 待重逢 | 园豆:10 (初学一级) | 2012-09-29 11:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册