Guest User

Untitled

a guest
Jun 8th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public class DbStatus
  2. {
  3. public static bool DbOnline()
  4. {
  5. const int MaxRetries = 10;
  6. int count = 0;
  7.  
  8. while (count < MaxRetries)
  9. {
  10. try
  11. {
  12. // Just access the database. any cheap query is ok since we don't care about the result.
  13. return true;
  14. }
  15. catch (Exception ex)
  16. {
  17. Thread.Sleep(30000);
  18. count++;
  19. }
  20. }
  21. return false;
  22. }
  23. }
  24.  
  25. processInstaller.Account = ServiceAccount.LocalSystem;
  26. processInstaller.Username = null;
  27. processInstaller.Password = null;
  28.  
  29. using (ServiceInstaller installer = new ServiceInstaller())
  30.  
  31. {
  32. installer.DisplayName = "yourservice.";
  33. installer.StartType = ServiceStartMode.Automatic;
  34. installer.ServiceName = "YourService";
  35.  
  36.  
  37.  
  38. installer.ServicesDependedOn = new string [] { "DependenceService" };
  39. this.Installers.Add(processInstaller);
  40. this.Installers.Add(installer);
  41.  
  42. }
Add Comment
Please, Sign In to add comment