File size: 1,296 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading;

using Codice.LogWrapper;

namespace Unity.PlasticSCM.Editor.UI
{
    internal static class GUIActionRunner
    {
        internal delegate void ActionDelegate();

        internal static void RunGUIAction(ActionDelegate action)
        {
            if (EditorDispatcher.IsOnMainThread)
            {
                action();
                return;
            }

            lock (mLock)
            {
                ManualResetEvent syncEvent = new ManualResetEvent(false);

                EditorDispatcher.Dispatch(delegate {
                    try
                    {
                        action();
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat("GUI action failed: {0}", e.Message);
                        mLog.DebugFormat("Stack trace:{0}{1}", Environment.NewLine, e.StackTrace);
                        throw;
                    }
                    finally
                    {
                        syncEvent.Set();
                    }
                });

                syncEvent.WaitOne();
            }
        }

        static object mLock = new object();

        static readonly ILog mLog = LogManager.GetLogger("GUIActionRunner");
    }
}