自终止窗口服务 [英] Self terminating windows service

查看:66
本文介绍了自终止窗口服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我写了一个Windows服务,该服务应该在指定金额后停止。
时间。我在指定时间后调用OnStop()。 OnStop()方法

已执行但我没有看到服务停止。


请告知如何停止服务。


谢谢,

SP

Hi All,

I wrote a windows service which is supposed to stop after specified amount
of time. I am calling OnStop() after specified time. OnStop() methods
executed but I dont see the service stopping.

Please advise how to stop the service.

Thanks,
SP

推荐答案

SP,


我不要认为这是一个好主意,因为服务的概念是

它应该一直在运行。


如果你需要一个进程在某个时间运行,然后我会建议创建一个可执行文件并将其设置为计划任务

在某个时间运行,然后在运行一段时间后将自行关闭。


如果必须使用服务,则使用ServiceController类得到

服务并将其关闭。


希望这会有所帮助。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse 。 com

" SP" < EA*@sp.com>在消息中写道

新闻:ey ************* @ TK2MSFTNGP10.phx.gbl ...
SP,

I don''t think that this is a good idea, since the idea of a service is
that it is supposed to be always running.

If you have a need for a process to run at a certain time, then I would
recommend creating an executable and setting it up as a scheduled task which
runs at a certain time, and then will shut itself down after being run for a
certain amount of time.

If you must use a service, then use the ServiceController class to get
the service and shut it down.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SP" <EA*@sp.com> wrote in message
news:ey*************@TK2MSFTNGP10.phx.gbl...
大家好,
我写了一个Windows服务,应该在指定数量的时间后停止。我在指定时间后调用OnStop()。 OnStop()方法已执行但我没有看到服务停止。

请告知如何停止服务。

谢谢,
SP
Hi All,

I wrote a windows service which is supposed to stop after specified amount
of time. I am calling OnStop() after specified time. OnStop() methods
executed but I dont see the service stopping.

Please advise how to stop the service.

Thanks,
SP



您好Nicholas,


感谢您的回复。让我简要介绍一下我想要实现的目标。


作为我正在研究的框架的一部分,我有一个控制台应用程序, a

Windows服务。控制台应用程序使用Windows服务执行期间

控制台应用程序多次调用Windows服务。我使用了

ServiceController来启动和停止。这部分运行正常。


问题是,我使windows服务成为一个独立的组件,可以从服务控制台执行
。现在这个服务的任务是生成一个csv文件,并继续向它添加记录,直到它停止。所以只要

确保Windows服务不会继续添加记录并耗尽所有硬盘空间由于人为错误,我想限制
由服务添加的行。一旦添加了指定的行数,我就会想要终止服务。截至目前,我限制了行数。

但服务本身并没有停止。


请告诉我,无论我们能做什么那个。


谢谢,


SP


" Nicholas Paldino [.NET / C# MVP] QUOT; < mv*@spam.guard.caspershouse.com>写在

消息新闻:呃************** @ TK2MSFTNGP12.phx.gbl ...
Hi Nicholas,

Thank you for your reply. Let me give a brief background about what I am
trying to achieve.

As a part of framework I am working on, I have a console application and a
Windows service. Console application uses windows service. During execution
console application calls windows service multiple times. I used
ServiceController to start and stop. This part is running fine.

The issue is, I made windows service a stand alone components which can be
executed from services console. Now the task of this service is to generate
a csv file and keep on adding records to it till it is stopped. So just to
make sure that windows service does not keeps on adding records and exhaust
all hard disk space because of human error, I wanted to limit the number of
lines added by the service. Once the specified number of lines are added, I
want to terminate the service. As of now I am limiting the number of lines.
But the service itself is not stopping.

Please let me know whether there is anyway we can do that.

Thanks,

SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uh**************@TK2MSFTNGP12.phx.gbl...
SP,
我不认为这是一个好主意,因为服务的概念是应该一直运行。

如果你有一个需要一个进程在某个时间运行,然后I
会建议创建一个可执行文件并将其设置为在某个时间运行的计划任务
,然后在运行后自行关闭
a一定的时间。

如果你必须使用服务,那么使用ServiceController类获取服务并关闭它。
希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

" SP" < EA*@sp.com>在消息中写道
新闻:ey ************* @ TK2MSFTNGP10.phx.gbl ...
SP,

I don''t think that this is a good idea, since the idea of a service is
that it is supposed to be always running.

If you have a need for a process to run at a certain time, then I would recommend creating an executable and setting it up as a scheduled task which runs at a certain time, and then will shut itself down after being run for a certain amount of time.

If you must use a service, then use the ServiceController class to get
the service and shut it down.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SP" <EA*@sp.com> wrote in message
news:ey*************@TK2MSFTNGP10.phx.gbl...
大家好,
我写了一个Windows服务,应该在指定的
时间后停止。我在指定时间后调用OnStop()。 OnStop()方法已执行但我没有看到服务停止。

请告知如何停止服务。

谢谢,
SP
Hi All,

I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods
executed but I dont see the service stopping.

Please advise how to stop the service.

Thanks,
SP




SP,


听起来你基本上想要分享从多个

来源访问一个文件,对吗?


一个服务IMO对此很大。


相反,你应该在类中使用Mutex来阻止访问试图写入文件的其他

进程。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse .com


" SP" < EA*@sp.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP11.phx.gbl ...
SP,

It sounds like you basically want shared access to a file from multiple
sources, right?

A service IMO is massive overkill for this.

Rather, you should use a Mutex in a class to block access to other
processes trying to write to the file.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SP" <EA*@sp.com> wrote in message
news:Oi*************@TK2MSFTNGP11.phx.gbl...
嗨尼古拉斯,
感谢您的回复。让我简要介绍一下我想要实现的目标。

作为我正在开发的框架的一部分,我有一个控制台应用程序和一个Windows服务。控制台应用程序使用Windows服务在
执行期间,控制台应用程序多次调用Windows服务。我使用了
ServiceController来启动和停止。这部分运行正常。

问题是,我使windows服务成为一个独立的组件,可以从服务控制台执行。现在这项服务的任务是生成一个csv文件并继续添加记录直到它停止。所以只是为了确保Windows服务不会继续添加记录并且因为人为错误而耗尽所有硬盘空间,我想限制数量
/>由服务添加的行。一旦添加了指定的行数,
我想终止服务。截至目前,我限制了
线的数量。
但是服务本身并没有停止。

请告诉我,无论如何我们都能做到。

谢谢,

Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>在消息新闻中写道
:嗯************** @ TK2MSFTNGP12.phx.gbl ...
Hi Nicholas,

Thank you for your reply. Let me give a brief background about what I am
trying to achieve.

As a part of framework I am working on, I have a console application and a
Windows service. Console application uses windows service. During
execution
console application calls windows service multiple times. I used
ServiceController to start and stop. This part is running fine.

The issue is, I made windows service a stand alone components which can be
executed from services console. Now the task of this service is to
generate
a csv file and keep on adding records to it till it is stopped. So just to
make sure that windows service does not keeps on adding records and
exhaust
all hard disk space because of human error, I wanted to limit the number
of
lines added by the service. Once the specified number of lines are added,
I
want to terminate the service. As of now I am limiting the number of
lines.
But the service itself is not stopping.

Please let me know whether there is anyway we can do that.

Thanks,

SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uh**************@TK2MSFTNGP12.phx.gbl...
SP,
我不认为这是一个好主意,因为服务的概念
它应该一直在运行。

如果您需要在特定时间运行进程,那么我
SP,

I don''t think that this is a good idea, since the idea of a service
is
that it is supposed to be always running.

If you have a need for a process to run at a certain time, then I


建议创建可执行文件并将其设置为计划任务
recommend creating an executable and setting it up as a scheduled task


哪个

在某个时间运行,然后在运行后自行关闭
runs at a certain time, and then will shut itself down after being run
for


一定的时间。

如果你必须使用服务,那么使用ServiceController类来获取服务并关闭它。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard。 caspershouse.com

" SP" < EA*@sp.com>在消息中写道
新闻:ey ************* @ TK2MSFTNGP10.phx.gbl ...
certain amount of time.

If you must use a service, then use the ServiceController class to
get
the service and shut it down.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SP" <EA*@sp.com> wrote in message
news:ey*************@TK2MSFTNGP10.phx.gbl...
>大家好,
>
>我写了一个Windows服务,应该在指定数量后停止>时间我在指定时间后调用OnStop()。 OnStop()方法
>执行但我没有看到服务停止。
>
>请告知如何停止服务。
>
>谢谢,
> SP
>
>
> Hi All,
>
> I wrote a windows service which is supposed to stop after specified amount > of time. I am calling OnStop() after specified time. OnStop() methods
> executed but I dont see the service stopping.
>
> Please advise how to stop the service.
>
> Thanks,
> SP
>
>





这篇关于自终止窗口服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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