Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public class RecurringJob : IJob, IRegisteredObject
  2. {
  3. private static readonly object currentLock = new object();
  4. private static bool active = false;
  5.  
  6. private static bool CanContinue {
  7. get {
  8. lock(currentLock){
  9. return !active;
  10. }
  11. }
  12. }
  13.  
  14. public RecurringJob()
  15. {
  16. //code to setup job
  17. }
  18.  
  19. public void Execute()
  20. {
  21. if (CanContinue)
  22. {
  23. active = true;
  24. //do work here
  25. active = false;
  26. }
  27. }
  28.  
  29. public void Stop(bool immediate)
  30. {
  31. //code to handle application stopping graefully
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement