473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Self terminating windows service

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
Nov 16 '05 #1
9 7205
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...
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

Nov 16 '05 #2
SP
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 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...
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


Nov 16 '05 #3
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...
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 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...
> 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
>
>



Nov 16 '05 #4
SP
Nicholas,

No, I am not looking for shared access. I am using this windows service to
read performance counters. The framework is utitlized for testing some
applications and at that time I want to check the performance counters. I
used a service for this task. Users have an option of starting and stopping
the service with out using console applpication. Each time service is
started it creates a new file with what ever performance counters user
wishes to capture.

So I guess there is either no easy way or no way we can have service stop
itself.

Thanks,
Sasidhar.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uF**************@tk2msftngp13.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...
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 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...
> 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
>
>



Nov 16 '05 #5
SP,

Once again, I have to say this is overkill. If you want to get
performance counter information, why not just use the PerformanceCounter
class in your console application, and have it write the file?

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

"SP" <EA*@sp.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Nicholas,

No, I am not looking for shared access. I am using this windows service to
read performance counters. The framework is utitlized for testing some
applications and at that time I want to check the performance counters. I
used a service for this task. Users have an option of starting and
stopping
the service with out using console applpication. Each time service is
started it creates a new file with what ever performance counters user
wishes to capture.

So I guess there is either no easy way or no way we can have service stop
itself.

Thanks,
Sasidhar.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uF**************@tk2msftngp13.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...
> 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 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...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #6
SP
Nicholas,

Thank you. I found this link online.

http://dotnetjunkies.com/WebLog/jdix.../27/26931.aspx

SP
"SP" <EA*@sp.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Nicholas,

No, I am not looking for shared access. I am using this windows service to
read performance counters. The framework is utitlized for testing some
applications and at that time I want to check the performance counters. I
used a service for this task. Users have an option of starting and stopping the service with out using console applpication. Each time service is
started it creates a new file with what ever performance counters user
wishes to capture.

So I guess there is either no easy way or no way we can have service stop
itself.

Thanks,
Sasidhar.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uF**************@tk2msftngp13.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...
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 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...
> > 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
> >
> >
>
>



Nov 16 '05 #7
SP
Nicholas,

I haven't done that much research before implementing this solution. But
here are my observations.

I implemented both a console app and service. Both achieve the same. While I
see that windows service is using few of my system resources, console
application is consuming more processing power. I dont want my performance
counter reader to consume more resources. I dont know whether my argument
makes that much sense or not but I am sure about my observation that console
app is consuming more resources for this specific application..

Thanks,
SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O9**************@TK2MSFTNGP15.phx.gbl...
SP,

Once again, I have to say this is overkill. If you want to get
performance counter information, why not just use the PerformanceCounter
class in your console application, and have it write the file?

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

"SP" <EA*@sp.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Nicholas,

No, I am not looking for shared access. I am using this windows service to read performance counters. The framework is utitlized for testing some
applications and at that time I want to check the performance counters. I used a service for this task. Users have an option of starting and
stopping
the service with out using console applpication. Each time service is
started it creates a new file with what ever performance counters user
wishes to capture.

So I guess there is either no easy way or no way we can have service stop itself.

Thanks,
Sasidhar.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uF**************@tk2msftngp13.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...
> 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 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...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #8
SP,

Lets assume that reading the performance counters has a cost of X. Now
running a console app has a cost of Y, and running a service has a cost of
Z. When I say running a console app or service, I mean running just the
console, or the service, not the performance counter in the service.

So now, if you do it all in the console app, you have a cost of X + Y.
If you do it in the service, and have the console app activate the service,
you have a cost of X + Y + Z.

This is an oversimplification, I admit.

In reality, reading the performance counters in a service versus a
console app are going to both take up the same amount of processing power,
since they are doing the same thing. Just because you take the code that is
consuming resources and putting it somewhere else doesn't mean that it isn't
paying the price for performing those operations.

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

"SP" <EA*@sp.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Nicholas,

I haven't done that much research before implementing this solution. But
here are my observations.

I implemented both a console app and service. Both achieve the same. While
I
see that windows service is using few of my system resources, console
application is consuming more processing power. I dont want my performance
counter reader to consume more resources. I dont know whether my argument
makes that much sense or not but I am sure about my observation that
console
app is consuming more resources for this specific application..

Thanks,
SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:O9**************@TK2MSFTNGP15.phx.gbl...
SP,

Once again, I have to say this is overkill. If you want to get
performance counter information, why not just use the PerformanceCounter
class in your console application, and have it write the file?

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

"SP" <EA*@sp.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
> Nicholas,
>
> No, I am not looking for shared access. I am using this windows service to > read performance counters. The framework is utitlized for testing some
> applications and at that time I want to check the performance counters. I > used a service for this task. Users have an option of starting and
> stopping
> the service with out using console applpication. Each time service is
> started it creates a new file with what ever performance counters user
> wishes to capture.
>
> So I guess there is either no easy way or no way we can have service stop > itself.
>
> Thanks,
> Sasidhar.
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:uF**************@tk2msftngp13.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...
>> > 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 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...
>> >> > 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
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 16 '05 #9
SP
I am not quite sure about how console applications and windows services are
handled by .NET framework. Putting everything into a console application has
few drawbacks. You will need to do thread processing because my console
application also does something other than starting and stopping the
service. The other thing is.. you cant control the program independently.
When I implemented thread processing my application was using lot of
resources. Using this approach my application never exceeded 2% CPU
utilization.

I used to believe in this
"Just because you take the code that is consuming resources and putting it
somewhere else doesn't mean that it isn't paying the price for performing
those operations."

But now I am not sure now... May be my application architecture was bad when
I had multi-thread solution.

My idea of separating is also driven by the thought of having multiple
independent services which can be reused. Influenced by SOA.

Thanks,
SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#H*************@TK2MSFTNGP12.phx.gbl...
SP,

Lets assume that reading the performance counters has a cost of X. Now running a console app has a cost of Y, and running a service has a cost of
Z. When I say running a console app or service, I mean running just the
console, or the service, not the performance counter in the service.

So now, if you do it all in the console app, you have a cost of X + Y.
If you do it in the service, and have the console app activate the service, you have a cost of X + Y + Z.

This is an oversimplification, I admit.

In reality, reading the performance counters in a service versus a
console app are going to both take up the same amount of processing power,
since they are doing the same thing. Just because you take the code that is consuming resources and putting it somewhere else doesn't mean that it isn't paying the price for performing those operations.

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

"SP" <EA*@sp.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Nicholas,

I haven't done that much research before implementing this solution. But
here are my observations.

I implemented both a console app and service. Both achieve the same. While I
see that windows service is using few of my system resources, console
application is consuming more processing power. I dont want my performance counter reader to consume more resources. I dont know whether my argument makes that much sense or not but I am sure about my observation that
console
app is consuming more resources for this specific application..

Thanks,
SP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:O9**************@TK2MSFTNGP15.phx.gbl...
SP,

Once again, I have to say this is overkill. If you want to get
performance counter information, why not just use the PerformanceCounter class in your console application, and have it write the file?

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

"SP" <EA*@sp.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
> Nicholas,
>
> No, I am not looking for shared access. I am using this windows service
to
> read performance counters. The framework is utitlized for testing
some > applications and at that time I want to check the performance counters. I
> used a service for this task. Users have an option of starting and
> stopping
> the service with out using console applpication. Each time service is
> started it creates a new file with what ever performance counters
user > wishes to capture.
>
> So I guess there is either no easy way or no way we can have service

stop
> itself.
>
> Thanks,
> Sasidhar.
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:uF**************@tk2msftngp13.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...
>> > 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 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...
>> >> > 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
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
2
by: Russ McDaniel | last post by:
Originally posted to microsoft.public.dotnet.distributed_apps with no response. Reposted here with additional thoughts. --- Hello, I'm writing a Windows service which performs some...
0
by: Stefan Krah | last post by:
Hello, I'm trying to run a Python script as a Windows service with a defined shutdown. The script (enigma-client.py) handles the communications with the server in a distributed computing effort...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
0
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
0
by: Rudy Schockaert | last post by:
After some Googling I found a post of someone who wanted to do exactly as what I want to do now. There is however a problem in his code that makes the service fails after the first connection. I...
6
by: BK | last post by:
I've created a windows service and tested it. It works the way I want it to. I added a ProjectInstaller and set the appropriate properties in my Windows Service project. To install it, I went to...
5
by: momobear | last post by:
I feel really puzzled about fellowing code, please help me finger out what problem here. import threading class workingthread(threading.Thread): def __init__(self): self.quitEvent =...
1
by: Michael Chesterton | last post by:
I'm trying to get a program that uses M2Crypto ThreadingSSLServer to run in windows as a service. I have a few problem, it doesn't listen on its port and I don't know how to debug it. I used the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.