Exemple #1
0
        public void TestThread()
        {
            int currentThreadID = Thread.CurrentThread.ManagedThreadId;
            int testThreadId    = -1;

            var logHandler = new LogHandler(() => testThreadId = Thread.CurrentThread.ManagedThreadId);

            using (UnityDebug.TemporaryLogHandler(logHandler))
            {
                Task.Run(() => Debug.Log(Str)).Wait();

                Assert.IsTrue(testThreadId != -1);
                Assert.AreNotEqual(currentThreadID, testThreadId);
            }
        }
Exemple #2
0
        public void TestThreadSafe()
        {
            var asyncLock = new object();

            var logHandler = new LogHandler(delegate()
            {
                Monitor.Enter(asyncLock);
                Thread.Sleep(200);
                Monitor.Exit(asyncLock);
            });

            using (UnityDebug.TemporaryLogHandler(logHandler))
            {
                var task = Task.Run(() => Debug.Log(Str));

                logHandler.CallBack = delegate()
                {
                    Assert.IsFalse(Monitor.IsEntered(asyncLock));
                };
                Debug.Log(Str);

                task.Wait();
            }
        }