No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GUIActionRunner.cs 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Threading;
  3. using Codice.LogWrapper;
  4. namespace Unity.PlasticSCM.Editor.UI
  5. {
  6. internal static class GUIActionRunner
  7. {
  8. internal delegate void ActionDelegate();
  9. internal static void RunGUIAction(ActionDelegate action)
  10. {
  11. if (EditorDispatcher.IsOnMainThread)
  12. {
  13. action();
  14. return;
  15. }
  16. lock (mLock)
  17. {
  18. ManualResetEvent syncEvent = new ManualResetEvent(false);
  19. EditorDispatcher.Dispatch(delegate {
  20. try
  21. {
  22. action();
  23. }
  24. catch (Exception e)
  25. {
  26. mLog.ErrorFormat("GUI action failed: {0}", e.Message);
  27. mLog.DebugFormat("Stack trace:{0}{1}", Environment.NewLine, e.StackTrace);
  28. throw;
  29. }
  30. finally
  31. {
  32. syncEvent.Set();
  33. }
  34. });
  35. syncEvent.WaitOne();
  36. }
  37. }
  38. static object mLock = new object();
  39. static readonly ILog mLog = PlasticApp.GetLogger("GUIActionRunner");
  40. }
  41. }