code_junkie

How/Where to handle ConfigurationErrorsException in a windows service

Nov 13th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. //ProcessingSleepTime Property
  2. [ConfigurationProperty("ProcessingSleepTime", DefaultValue = 1000, IsRequired = false)]
  3. [IntegerValidator(MinValue = 5, MaxValue = 60000)]
  4. public Int32 ProcessingSleepTime
  5. {
  6. get
  7. {
  8. if (this["ProcessingSleepTime"] == null)
  9. return 100;
  10.  
  11. return (Int32)this["ProcessingSleepTime"];
  12. }
  13. set
  14. {
  15. this["ProcessingSleepTime"] = value;
  16. }
  17. }
  18.  
  19. int GetIntFromConfigSetting(string settingName, int defaultValue)
  20. {
  21. int retValue = defaultValue;
  22. if(this.ContainsKey(settingName))
  23. {
  24. int sleepInterval;
  25. if(Int32.TryParse(this[settingName], out sleepInterval)
  26. {
  27. retValue = sleepInterval;
  28. }
  29. }
  30. return retValue;
  31. }
  32.  
  33. int retValue = 100;
  34. if(this.ContainsKey("ProcessingSleepTime"))
  35. {
  36. object sleepTime = this["ProcessingSleepTime"];
  37. int sleepInterval;
  38. if(Int32.TryParse(sleepTime.ToString(), out sleepInterval)
  39. {
  40. retValue = sleepInterval;
  41. }
  42. }
  43. return retValue;
Add Comment
Please, Sign In to add comment