Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public void SaveSettings(SettingsType settingsType)
  2. {
  3. if (!File.Exists(_settingsFile))
  4. {
  5. File.Create(_settingsFile);
  6. }
  7.  
  8. var xmlDoc = XDocument.Load(_settingsFile);
  9.  
  10. switch (settingsType)
  11. {
  12. case SettingsType.Measurement:
  13. SaveMeasurementSettings(ref xmlDoc);
  14. break;
  15. case SettingsType.Display:
  16. SaveDisplaySettings(ref xmlDoc);
  17. break;
  18. case SettingsType.Common:
  19. SaveCommonSettings(ref xmlDoc);
  20. break;
  21. case SettingsType.View:
  22. SaveViewSettings(ref xmlDoc);
  23. break;
  24. case SettingsType.InputChannel:
  25. SaveInputChannelSettings(ref xmlDoc);
  26. break;
  27. default:
  28. break;
  29. }
  30. xmlDoc.Save(_settingsFile);
  31. }
  32.  
  33. public void Save(string xmlFilePath)
  34. {
  35. Thread thread = new Thread(new ParameterizedThreadStart(SaveSettings));
  36. thread.Start(xmlFilePath);
  37. }
  38.  
  39. private void SaveSettings(object data)
  40. {
  41. string xmlFilePath;
  42. if ((xmlFilePath = data as string) != null)
  43. {
  44. this.SaveSettingsFile(xmlFilePath);
  45. }
  46. }
  47.  
  48. private void SaveSettingsFile(string xmlFilePath)
  49. {
  50. // Save the file contents
  51. }
  52.  
  53. public class SettingsType {}
  54.  
  55. public class Settings
  56. {
  57. private Thread _worker;
  58.  
  59. public void SaveSettings(SettingsType type)
  60. {
  61. // save logic
  62. }
  63.  
  64. public void BeginSaveSettings(SettingsType type)
  65. {
  66. _worker = new Thread(() => SaveSettings(type)) {IsBackground = true};
  67. _worker.Start();
  68. }
  69.  
  70. public bool EndSaveSettings(TimeSpan timeOut)
  71. {
  72. return _worker.Join(timeOut);
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement