什么是最大的时间窗口服务等来处理停止请求 [英] what is the maximum time windows service wait to process stop request

查看:171
本文介绍了什么是最大的时间窗口服务等来处理停止请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个窗口服务在处理大量数据的C#。当我们停止尝试了一段时间20/30秒,然后抛出异常。

I have written a windows service in c# that process a lot data. when we stop it try for sometime 20/30 seconds and then throws exception.

我想的onStop事件推行ServiceBase.RequestAdditionalTime()。

I want to implement ServiceBase.RequestAdditionalTime() in OnStop event.

我想知道之后,Windows服务抛出异常的确切超时,这样我可以只是之前它要求额外的时间。

I want to know the exact timeout after which windows service throws the exception, so that I can request additional time just before it.

我搜查,但没有找到这个默认停止超时值。

I searched but did not find this default stop timeout value.

推荐答案

我写了下面code来实现它。

I wrote the following code to achieve it.

protected override void OnStop()
{
  int timeout = 10000;
  var task = Task.Factory.StartNew(() => MyTask());
  while (!task.Wait(timeout))
  {
      RequestAdditionalTime(timeout);
  }
}

在code启动一个任务,每10秒钟后检查任务完成与否,如果没有完成它要求额外的10秒,继续检查,直到任务完成。

The code start a Task and check after every 10 seconds if task is completed or not, if it is not completed it requests additional 10 seconds and keep checking till task completion.

这篇关于什么是最大的时间窗口服务等来处理停止请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆