Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:13:31+00:00 2026-06-13T04:13:31+00:00

Basically I need my application to run from system start until system shutdown. I

  • 0

Basically I need my application to run from system start until system shutdown. I figured out the following approach:

  1. create MyApp.exe and MyService.exe
  2. MyApp should install MyService as a service
  3. MyService is supposed to run at startup and periodically check if MyApp is running. If it’s not than start it.

That’s the code I wrote for my service:

protected override void OnStart(string[] args)
{
    while(true)
    {
        int processesCount =
            Process.GetProcessesByName(Settings.Default.MyAppName).Count() +
            Process.GetProcessesByName(Settings.Default.MyAppName + ".vshost").Count() +
            Process.GetProcessesByName(Settings.Default.MyAppUpdaterName).Count();

        if(processesCount==0)
        {
            //restore
            var p = new Process { StartInfo = { FileName = Settings.Default.MyAppName, Arguments = "" } };
            p.Start();
        }
        else
        {
        }

        System.Threading.Thread.Sleep(3000);
    }
}
  1. How can I install this process so that it starts on windows start?
  2. I’m not sure if this infinite loop in OnStart method is a good idea. Is it?
  3. Is the general idea ok?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:13:32+00:00Added an answer on June 13, 2026 at 4:13 am

    Is the general idea ok?

    As Hans points out in comments this is hostile to the user and fortunately won’t work on Vista or later because services run in their own windows station. Put whatever logic you need to run all the time in the service and use an IPC mechanism such as WCF to communicate with an (optionally) running UI. If the user disables the service or exits the GUI respect their wishes…

    How can I install this process so that it starts on windows start?

    Add an entry to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run or HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Runthat points to your GUI application.

    I’m not sure if this infinite loop in OnStart method is a good idea.
    Is it?

    No. You need to return from OnStart if you need to do work after OnStart returns create a Thread to do that work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically the above, I need my mobile application (which is built with Trigger) to
I need to write cross platform application (basically CRUD). Is usage of Java Swing
Basically multiple instances of our application will be launched but they need to have
I need some help choosing databases for my application. My web application will basically
Basically, I have a graphical swing application. I need to use UDP to send
I need to run a local application on a windows CE 6.0 platform I
I have a new mobile application I need to get out the door but
We're trying to design a new addition to our application. Basically we need to
I just need help. Basically I am creating a windows appllication that sends bulk
Basically need to generate custom(some different then yes no) messeges(alert) in JS , how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.