TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mary jean ligas
NA
420
195.9k
windows service application can detect its own status?
Jun 19 2017 5:55 AM
is there a way that a windows service application can detect its own status upon restarting the service itself?
i want to handle that if a user restart the service and the status is still start pending because the service finish the execution of methods then it wont allow to restart it. How can i do that? I do some code on the OnStart part but the error shows that "The service on local computer started and then stopped. Some services stop automatically if they are not in the use by other services of programs."
here's my snippet:
protected override void OnStart(string[] args)
{
using (ServiceController sc = new ServiceController(ServiceName))
{
if(sc.Status == ServiceControllerStatus.StartPending)
{
//will not allow to restart the service
}
else
{
//call methods
}
}
}
Reply
Answers (
1
)
Windows Form With MSSQL Connectivity
Accessing XAML from non-main class