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]" <
[email protected]>
wrote
in
message 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]
- (e-mail address removed)
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]" <
[email protected]>
wrote
in
message 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]
- (e-mail address removed)
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