예제 #1
0
        public void TestAbortThread()
        {
            Lock sync = new Lock();
            TimedCondition aborted = new TimedCondition(sync);
            Thread testThread = new Thread(delegate()
            {
                try
                {
                    Log("Test thread sleeping for 8 seconds..");
                    Thread.Sleep(8000);
                }
                catch (ThreadAbortException)
                {
                    Log("Test thread aborted..");
                    aborted.Signal();
                }
                Fail("This line should never be executed");
            });
            testThread.Start();
            sync.Acquire();
            Log("Aborting test thread in 2 seconds.  Sleeping...");
            Thread.Sleep(2000);
            Log("...awake!  Going to abort the test thread.");
            testThread.Abort();
            Log("Called testThread.Abort()");

            try
            {
                aborted.Await(12000);
            }
            catch (ConditionTimedOutException)
            {
                Fail("Thread was not aborted as expected!");
            }
        }
예제 #2
0
    protected void DrawCondition(Rect pos, TimedCondition condition, GUIContent label)
    {
        EditorGUI.LabelField(InLine.GetRect(pos, 0, 0, 2), "Timer Amount");
        condition.timerAmount = EditorGUI.FloatField(InLine.GetRect(pos, 0, 100, 1), condition.timerAmount);

        InLine.SetRect(pos, 1, 0, 6);
        {
            EditorGUI.LabelField(InLine.NextRect(), "Loop");
            condition.loop = EditorGUI.Toggle(InLine.NextRect(true), condition.loop);
        }
        InLine.Reset();
    }
예제 #3
0
        public object Call(string method, object[] args, int timeout)
        {
            XmlHttpRequest xhr = XmlHttpRequestManager.GetXmlHttpRequest();
            Lock l = new Lock();
            l.Acquire();
            TimedCondition condition = new TimedCondition(l);
            OnReadyStateChangeHandler handler = new OnReadyStateChangeHandler(xhr, condition);
            xhr.OnReadyStateChange = (NativeFunction)new VoidDelegate(handler.OnReadyStateChange);
            xhr.Open("POST", ServerUrl, true, Username, Password);
            xhr.SetRequestHeader(RpcMethodRequestHeader, method);
            xhr.Send(Serialize(args));
            if (timeout > 0)
            {
                try
                {
                    // wait for timeout milliseconds
                    condition.Await(timeout);
                }
                catch (ConditionTimedOutException)
                {
                    Logging.Debug("Request timed out!!!");
                    throw new JsonRpcCallTimedOutException(this, method, args, timeout);
                }
            }
            else
            {
                // wait indefinitely
                condition.Await();
            }

            // we have a response from the server, or we couldn't connect
            Logging.Debug("Status code is: " + xhr.Status);
            if (xhr.Status == 200)
            {
                Logging.Debug("Got 200! Response text is " + xhr.ResponseText);
                return Deserialize(xhr.ResponseText);
            }
            else if (xhr.Status == 0)
            {
                Logging.Debug("Request timed out!!!");
                throw new JsonRpcCallTimedOutException(this, method, args, 1000); // TODO: Extract into constant of 1000 ms.  Also this should be some sort of connection refused exception instead
            }
            else
            {
                throw GenerateException(xhr.Status, method, args, xhr.ResponseText);
            }
        }
예제 #4
0
        public void TestAbortThreadWithState()
        {
            Lock sync = new Lock();
            TimedCondition aborted = new TimedCondition(sync);
            Thread testThread = new Thread(delegate()
            {
                try
                {
                    Log("Test thread sleeping for 8 seconds..");
                    Thread.Sleep(8000);
                }
                catch (ThreadAbortException e)
                {
                    if (e.ExceptionState != null && e.ExceptionState.ToString() == "Exception state")
                    {
                        Log("Test thread aborted with state: " + e.ExceptionState);
                        aborted.Signal();
                    }
                    else
                    {
                        Log("Test thread aborted with unknown state: " + e.ExceptionState);
                    }
                }
                Fail("This line should never be executed");
            });
            testThread.Start();
            sync.Acquire();
            Log("Aborting test thread in 2 seconds");
            Thread.Sleep(2000);
            testThread.Abort("Exception state");

            try
            {
                aborted.Await(12000);
            }
            catch (ConditionTimedOutException)
            {
                Fail("Thread was not aborted as expected!");
            }
        }