472,095 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,095 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 7024
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Michael Riggio | last post: by
2 posts views Thread by Russ McDaniel | last post: by
reply views Thread by Stefan Krah | last post: by
6 posts views Thread by D | last post: by
reply views Thread by Rudy Schockaert | last post: by
6 posts views Thread by BK | last post: by
5 posts views Thread by momobear | last post: by
1 post views Thread by Michael Chesterton | last post: by
reply views Thread by leo001 | last post: by

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.