Guest User

Untitled

a guest
Dec 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. ILog Log = new FileLog();
  6. try
  7. {
  8. HostFactory.Run(serviceConfig =>
  9. {
  10. serviceConfig.Service<ServiceManager>(serviceInstance =>
  11. {
  12. serviceInstance.ConstructUsing(() => new ServiceManager());
  13. serviceInstance.WhenStarted(execute => execute.Start());
  14. serviceInstance.WhenStopped(execute => execute.Stop());
  15. });
  16.  
  17. });
  18. }
  19. catch (Exception ex)
  20. {
  21. Console.WriteLine(ex);
  22. Log.Error("Program.Main", ex, LogType.Error);
  23. Console.ReadLine();
  24. };
  25. }
  26. }
  27.  
  28. class ServiceManager
  29. {
  30.  
  31. xxx.....
  32.  
  33. public bool Stop()
  34. {
  35. try
  36. {
  37. _log.Info("The service is stopping", LogType.Info);
  38. _service.StopExecuteProduceMessage();
  39. Task.WaitAll(_tasks.ToArray());
  40. _log.Info("The service is stopped", LogType.Info);
  41. }
  42. catch (Exception ex)
  43. {
  44. _log.Error("Stop", ex, LogType.Error);
  45. }
  46. return true;
  47. }
  48. }
Add Comment
Please, Sign In to add comment