Search code examples
c#windowsregistry

Auto restart of Application at machine restart hangs the application


I have a windows application developed in c#, starts automatically everyday when machine starts. By using this windows c# application we are launching an html application to show all the details which reads from this c# application. And this windows application before launches html, reads updated data from server if any available. My issue is when machine starts application also starts and unable to connect to server and goes idle and launches html application and the html application will not be able to communicate and get any data from the windows application.

But when manually again stop and start the windows application it start connect to server and launch html with proper data.

In registry settings we have give winlogon as c:\myapplication.exe. Is there any way to make my c# application should wait until the machine starts completely and load all network connections in the machine and later the application starts.

Any suggestions.

Regards Sangeetha


Solution

  • There are various options to achieve your result:

    1. Use Task Scheduler. The newer version of the task schedule has delay start a task function.Simply set it to execute your 'apps' ON LOGON with different delays.
    2. If your C# application is exposed as service, you could delay load the service with depends on

      • Click Start, click Run, and enter regedit.
      • Expand to the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
      • Right-click the service that you are trying to set a dependency for and select New -> Multi-string Value.
      • Rename the new value to DependOnService.
      • Double-click the DependOnService value and enter the dependent service name (from above) into the Value Data: field and click OK.
      • Close the registry editor.
      • Restart the server.
      • Source

    3.You could use free program like Start Up Delayer to delay your program

    4.You could create an infinite loop in your c# program and break once all your dependencies are loaded. E.g. checking your are able to connect to the server and so on.