public void Post_ToCopiedDispatcher_IsAsynchronous()
        {
            SynchronizationContext actionDispatcherSyncContext = null;

            using (ManualResetEvent completed = new ManualResetEvent(false))
            using (ManualResetEvent wait = new ManualResetEvent(false))
            using (ActionThread thread1 = new ActionThread())
            using (ActionThread thread2 = new ActionThread())
            {
                thread1.Start();
                thread2.Start();

                // Capture the second thread's SynchronizationContext and signal this thread when it's captured.
                actionDispatcherSyncContext = thread2.DoGet(() => { return SynchronizationContext.Current.CreateCopy(); });

                // Have the first thread do an synchronous Post to the second thread and then trigger the "completed" event.
                // The action queued to the second thread will wait for the "wait" event.

                thread1.Do(() =>
                {
                    actionDispatcherSyncContext.Post((state) => { wait.WaitOne(); }, null);
                    completed.Set();
                });

                bool completedSignalled = completed.WaitOne(100);
                Assert.IsTrue(completedSignalled, "ActionDispatcherSynchronizationContext.Post is not asynchronous");

                wait.Set();
            }
        }
Пример #2
0
        public void PeriodicTimer_Elapsed_CanChangeInterval()
        {
            TimeSpan interval = default(TimeSpan);

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer = new Timer();
                    timer.Elapsed += () =>
                    {
                        timer.Interval = TimeSpan.FromMilliseconds(1);
                        interval = timer.Interval;
                        timer.Cancel();
                    };
                    timer.AutoReset = true;
                    timer.Interval = TimeSpan.FromMilliseconds(0);
                    timer.Enabled = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.AreEqual(TimeSpan.FromMilliseconds(1), interval, "Interval should be honored when called from Elapsed");
        }
Пример #3
0
        public void PeriodicTimer_Elapsed_CanCancelTimer()
        {
            int actionCount = 0;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer = new Timer();
                    timer.Elapsed += () =>
                    {
                        ++actionCount;
                        timer.Cancel();
                    };
                    timer.AutoReset = true;
                    timer.Interval = TimeSpan.FromMilliseconds(0);
                    timer.Enabled = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.AreEqual(1, actionCount, "Timer did not honor Cancel when called from Elapsed");
        }
        public void Dispose_WithoutStart_Joins()
        {
            ActionThread thread = new ActionThread();
            using (thread)
            {
            }

            Assert.IsFalse(thread.IsAlive, "ActionThread did not implicitly join");
        }
        public void IsAliveProperty_AfterStart_IsTrue()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                Assert.IsTrue(thread.IsAlive, "ActionThread is not alive after starting");
            }
        }
        public void IsAliveProperty_AfterStartAndJoin_IsFalse()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.Join();

                Assert.IsFalse(thread.IsAlive, "ActionThread is alive after joining");
            }
        }
Пример #7
0
        public static NSThread Start(NSAction action)
        {
            if (action == null) {
                throw new ArgumentNullException ("action");
            }

            var thread = new ActionThread (action);
            thread.Start ();
            return thread;
        }
        public void ActionThreadGSO_WithinActionThread_DoesNotRequireInvoke()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture InvokeRequired from the ActionThread's context
                bool nestedInvokeRequired = thread.DoGet(() => { return new GenericSynchronizingObject().InvokeRequired; });

                Assert.IsFalse(nestedInvokeRequired, "GenericSynchronizingObject does require invoke within ActionThread");
            }
        }
        public void ActionThreadGSO_OutsideActionThread_DoesRequireInvoke()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture GenericSynchronizingObject
                GenericSynchronizingObject test = thread.DoGet(() => { return new GenericSynchronizingObject(); });

                Assert.IsTrue(test.InvokeRequired, "GenericSynchronizingObject does not require invoke for ActionThread");
            }
        }
Пример #10
0
        public void Action_QueuedBeforeStart_IsExecutedByThread()
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Do(() => threadId = Thread.CurrentThread.ManagedThreadId);
                thread.Start();
                thread.Join();

                Assert.AreEqual(thread.ManagedThreadId, threadId, "ActionThread ran in wrong thread context");
            }
        }
        public void Action_BeginInvokeThroughActionThreadGSO_RunsOnTheActionThread()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture GenericSynchronizingObject
                GenericSynchronizingObject test = thread.DoGet(() => { return new GenericSynchronizingObject(); });

                int actionThreadId = Thread.CurrentThread.ManagedThreadId;
                IAsyncResult result = test.BeginInvoke((MethodInvoker)(() => { actionThreadId = Thread.CurrentThread.ManagedThreadId; }), null);
                test.EndInvoke(result);

                Assert.AreEqual(thread.ManagedThreadId, actionThreadId, "GenericSynchronizingObject.BeginInvoke did not synchronize");
            }
        }
        public void Action_BeginInvokeThroughActionThreadGSO_Runs()
        {
            bool sawAction = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture GenericSynchronizingObject
                GenericSynchronizingObject test = thread.DoGet(() => { return new GenericSynchronizingObject(); });

                IAsyncResult result = test.BeginInvoke((MethodInvoker)(() => { sawAction = true; }), null);
                test.EndInvoke(result);

                Assert.IsTrue(sawAction, "GenericSynchronizingObject.BeginInvoke did not execute action");
            }
        }
Пример #13
0
        public GameSocketManager Start()
        {
            _actionThread = new ActionThread
                                {
                                    Name = "BLUEDOT-GameSocketThread"
                                };

            _actionThread.Start();
            _actionThread.Do(() =>
            {
                _listeningSocket = new ServerTcpSocket();
                _listeningSocket.AcceptCompleted += IncomingConnectedAccepted;
                _listeningSocket.Bind(Address, Port);
                _listeningSocket.AcceptAsync();
            });

            return this;
        }
Пример #14
0
        public void ActionWithTwoArguments_AfterSync_HasNotRun()
        {
            bool sawAction = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                Action<int, int> action = thread.DoGet(() =>
                {
                    return Sync.SynchronizeAction((int a1, int a2) => { sawAction = true; });
                });

                // The action should be run in the context of the ActionThread
                Assert.IsFalse(sawAction, "Action should not have run already");
            }
        }
        public void BoundAsyncAction_Invoked_ExecutesSynchronized()
        {
            int sawActionThread = Thread.CurrentThread.ManagedThreadId;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var action = context.AsyncBind(() => { sawActionThread = Thread.CurrentThread.ManagedThreadId; }, actionThreadSyncContext);
                action();
                thread.Join();

                Assert.AreEqual(thread.ManagedThreadId, sawActionThread, "Bound action was not synchronized");
            }
        }
Пример #16
0
        public void Timer_AfterCancel_IsDisabled()
        {
            bool enabled = true;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() =>
                {
                    using (Timer timer = new Timer())
                    {
                        timer.SetPeriodic(TimeSpan.FromMilliseconds(50));
                        timer.Cancel();
                        enabled = timer.Enabled;
                    }
                });
            }

            Assert.IsFalse(enabled, "Timer.Enabled should be false");
        }
Пример #17
0
        public void SyncedWaitCallback_Invoked_ReceivesParameter()
        {
            object parameter1 = new object();
            object arg1       = null;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                WaitCallback action = thread.DoGet(() =>
                {
                    return(Sync.SynchronizeWaitCallback((a1) => { arg1 = a1; }));
                });

                action(parameter1);
                thread.Join();

                Assert.AreSame(parameter1, arg1, "Action did not receive parameter");
            }
        }
    static void Main()
    {
        // Normally, a BackgroundWorker (BGW) used within a Console application
        //  will invoke its ProgressChanged and RunWorkerCompleted events on a
        //  ThreadPool thread. This defeats the purpose of using a BGW.

        // An ActionThread provides a SynchronizationContext that the BGW can use
        //  to marshal its ProgressChanged and RunWorkerCompleted back to the
        //  ActionThread thread instead of on a ThreadPool thread.

        Console.WriteLine("Main console thread ID is " + Thread.CurrentThread.ManagedThreadId +
                          " and is " + (Thread.CurrentThread.IsThreadPoolThread ? "" : "not ") + "a threadpool thread");

        // In this example, we kick off an ActionThread and then exit from Main.
        //  Since the ActionThread is a foreground thread, it will continue to
        //  run until it completes processing.
        ActionThread actionThread = new ActionThread();

        actionThread.Start();
        actionThread.Do(FirstAction);
    }
Пример #19
0
        public void SyncedActionWithOneArgument_Invoked_RunsSynchronized()
        {
            int actionThreadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                Action <int> action = thread.DoGet(() =>
                {
                    return(Sync.SynchronizeAction((int a1) => { actionThreadId = Thread.CurrentThread.ManagedThreadId; }));
                });

                // The action should be run in the context of the ActionThread
                action(13);
                thread.Join();

                Assert.AreEqual(thread.ManagedThreadId, actionThreadId, "Action did not run synchronized");
            }
        }
Пример #20
0
        public void SyncedWaitOrTimerCallback_Invoked_RunsSynchronized()
        {
            int actionThreadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                WaitOrTimerCallback action = thread.DoGet(() =>
                {
                    return(Sync.SynchronizeWaitOrTimerCallback((a1, a2) => { actionThreadId = Thread.CurrentThread.ManagedThreadId; }));
                });

                // The action should be run in the context of the ActionThread
                action(null, false);
                thread.Join();

                Assert.AreEqual(thread.ManagedThreadId, actionThreadId, "Action did not run synchronized");
            }
        }
Пример #21
0
        public void SyncedAsyncCallback_Invoked_ReceivesParameter()
        {
            TestAsyncResult parameter1 = new TestAsyncResult();
            IAsyncResult    arg1       = null;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                AsyncCallback action = thread.DoGet(() =>
                {
                    return(Sync.SynchronizeAsyncCallback((IAsyncResult a1) => { arg1 = a1; }));
                });

                action(parameter1);
                thread.Join();

                Assert.AreSame(parameter1, arg1, "Action did not receive parameter");
            }
        }
Пример #22
0
        public void SyncedActionWithTwoArguments_Invoked_ReceivesParameters()
        {
            int arg1 = 0;
            int arg2 = 0;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Have the ActionThread set "action"
                Action <int, int> action = thread.DoGet(() =>
                {
                    return(Sync.SynchronizeAction((int a1, int a2) => { arg1 = a1; arg2 = a2; }));
                });

                action(13, 17);
                thread.Join();

                Assert.AreEqual(13, arg1, "Action did not receive parameter");
                Assert.AreEqual(17, arg2, "Action did not receive parameter");
            }
        }
Пример #23
0
        public void SingleShotTimer_Elapsed_InvokesElapsedExactlyOnce()
        {
            int actionCount = 0;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer           = new Timer();
                    timer.Elapsed  += () => { ++actionCount; };
                    timer.AutoReset = false;
                    timer.Interval  = TimeSpan.FromMilliseconds(0);
                    timer.Enabled   = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.AreEqual(1, actionCount, "Timer did not run Elapsed exactly once");
        }
Пример #24
0
        public void PeriodicTimer_Elapsed_InvokesElapsedMoreThanOnce()
        {
            int actionCount = 0;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer           = new Timer();
                    timer.Elapsed  += () => { ++actionCount; };
                    timer.AutoReset = true;
                    timer.Interval  = TimeSpan.FromMilliseconds(0);
                    timer.Enabled   = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.IsTrue(actionCount > 1, "Timer did not run Elapsed more than once");
        }
        public void BoundSyncedFunc_Invoked_DecrementsSyncContextOperationCount()
        {
            bool sawOperationCompleted = false;

            using (CallbackContext context = new CallbackContext())
                using (ActionThread thread = new ActionThread())
                {
                    thread.Start();

                    // Capture the thread's SynchronizationContext
                    SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return(SynchronizationContext.Current); });

                    var syncContext = new Util.LoggingSynchronizationContext(actionThreadSyncContext)
                    {
                        OnOperationCompleted = () => { sawOperationCompleted = true; }
                    };

                    var action = context.Bind(() => { return(13); }, syncContext, false);
                    int result = action();

                    Assert.IsFalse(sawOperationCompleted, "Context decremented operation count");
                }
        }
        public void FailingAction_InvokedThroughActionThreadGSO_PreservesExceptionAsInnerException()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture GenericSynchronizingObject
                GenericSynchronizingObject test = thread.DoGet(() => { return(new GenericSynchronizingObject()); });

                Exception errorToThrow     = new MyException();
                Exception innerErrorCaught = null;
                try
                {
                    test.Invoke((MethodInvoker)(() => { throw errorToThrow; }), null);
                }
                catch (TargetInvocationException ex)
                {
                    innerErrorCaught = ex.InnerException;
                }

                Assert.AreSame(errorToThrow, innerErrorCaught, "Exception not preserved");
            }
        }
        public void BoundAsyncAction_Invoked_DecrementsSyncContextOperationCount()
        {
            bool sawOperationCompleted = false;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var syncContext = new LoggingSynchronizationContext(actionThreadSyncContext)
                {
                    OnOperationCompleted = () => { sawOperationCompleted = true; }
                };

                var action = context.AsyncBind(() => { }, syncContext, false);
                action();
                thread.Join();

                Assert.IsFalse(sawOperationCompleted, "Context decremented operation count");
            }
        }
        public void BoundAsyncAction_Invoked_IncrementsSyncContextOperationCount()
        {
            bool sawOperationStarted = false;

            using (CallbackContext context = new CallbackContext())
                using (ActionThread thread = new ActionThread())
                {
                    thread.Start();

                    // Capture the thread's SynchronizationContext
                    SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return(SynchronizationContext.Current); });

                    var syncContext = new Util.LoggingSynchronizationContext(actionThreadSyncContext)
                    {
                        OnOperationStarted = () => { sawOperationStarted = true; }
                    };

                    var action = context.AsyncBind(() => { }, syncContext, false);
                    action();
                    thread.Join();

                    Assert.IsFalse(sawOperationStarted, "Context incremented operation count");
                }
        }
        public void BoundSyncedFunc_Invoked_UsesSyncContext()
        {
            bool sawSync = false;

            using (CallbackContext context = new CallbackContext())
                using (ActionThread thread = new ActionThread())
                {
                    thread.Start();

                    // Capture the thread's SynchronizationContext
                    SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return(SynchronizationContext.Current); });

                    var syncContext = new Util.LoggingSynchronizationContext(actionThreadSyncContext)
                    {
                        OnPost = () => { sawSync = true; },
                        OnSend = () => { sawSync = true; }
                    };

                    var action = context.Bind(() => { return(13); }, syncContext, false);
                    int result = action();

                    Assert.IsTrue(sawSync, "Context did not use SyncContext for sync");
                }
        }
        public void InvalidBoundSyncedFunc_Invoked_DoesNotExecute()
        {
            int sawActionThread = Thread.CurrentThread.ManagedThreadId;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext and signal this thread when it's captured.
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var action = context.Bind(() => { sawActionThread = Thread.CurrentThread.ManagedThreadId; return 13; }, actionThreadSyncContext, false);
                context.Reset();
                int result = action();

                Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, sawActionThread, "Invalid action should not run");
            }
        }
Пример #31
0
 // Start is called before the first frame update
 void Start()
 {
     nodeInfoThread = UnityThreadHelper.CreateThread((Action)GetNodeDetails);
     InvokeRepeating("UpdateNode", 3f, updateDelay);
 }
        public void BoundSyncedFunc_Invoked_IncrementsSyncContextOperationCount()
        {
            bool sawOperationStarted = false;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var syncContext = new LoggingSynchronizationContext(actionThreadSyncContext)
                {
                    OnOperationStarted = () => { sawOperationStarted = true; }
                };

                var action = context.Bind(() => { return 13; }, syncContext, false);
                int result = action();

                Assert.IsFalse(sawOperationStarted, "Context incremented operation count");
            }
        }
        public void BoundSyncedAction_Invoked_UsesSyncContext()
        {
            bool sawSync = false;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var syncContext = new LoggingSynchronizationContext(actionThreadSyncContext)
                {
                    OnPost = () => { sawSync = true; },
                    OnSend = () => { sawSync = true; }
                };

                var action = context.Bind(() => { }, syncContext, false);
                action();

                Assert.IsTrue(sawSync, "Context did not use SyncContext for sync");
            }
        }
Пример #34
0
 public void SyncAction_QueuedAfterJoin_ThrowsThreadStateException()
 {
     using (ActionThread thread = new ActionThread())
     {
         thread.Start();
         thread.Join();
         thread.DoSynchronously(() => { });
     }
 }
Пример #35
0
        public void SyncContext_FromInsideAction_SendsToSameThread()
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                // Use the SynchronizationContext to give the ActionThread more work to do
                actionThreadSyncContext.Send((state) => { threadId = Thread.CurrentThread.ManagedThreadId; }, null);

                Assert.AreEqual(thread.ManagedThreadId, threadId, "ActionThread ran in wrong thread context");
            }
        }
Пример #36
0
 private void UpdateNode()
 {
     nodeInfoThread = UnityThreadHelper.CreateThread((Action)GetNodeDetails);
 }
Пример #37
0
 public void FetchNodeList()
 {
     nodeListThread = UnityThreadHelper.CreateThread((Action)GetNodesList);
 }
Пример #38
0
        public void SyncFunc_QueuedAfterStart_PreservesReturnValue()
        {
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                object obj = thread.DoGet(() => { return new object(); });
                Assert.IsNotNull(obj, "ActionThread did not return result");
            }
        }
Пример #39
0
        public void SyncFunc_QueuedAfterStart_IsExecutedByThread()
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                object obj = thread.DoGet(() => { threadId = Thread.CurrentThread.ManagedThreadId; return new object(); });

                Assert.AreEqual(thread.ManagedThreadId, threadId, "ActionThread ran in wrong thread context");
            }
        }
        public void InvalidBoundSyncedFunc_Invoked_DoesSync()
        {
            bool sawSync = false;

            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext and signal this thread when it's captured.
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var syncContext = new LoggingSynchronizationContext(actionThreadSyncContext)
                {
                    OnPost = () => { sawSync = true; },
                    OnSend = () => { sawSync = true; }
                };

                var action = context.Bind(() => { return 13; }, syncContext, false);
                context.Reset();
                int result = action();

                Assert.IsTrue(sawSync, "Context did not use SyncContext for sync");
            }
        }
        public void InvalidBoundSyncedFunc_Invoked_ReturnsDefault()
        {
            using (CallbackContext context = new CallbackContext())
            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext and signal this thread when it's captured.
                SynchronizationContext actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                var action = context.Bind(() => { return 13; }, actionThreadSyncContext, false);
                context.Reset();
                int result = action();

                Assert.AreEqual(0, result, "Invalid Func returned a non-default value");
            }
        }
        public void Send_IsSynchronous()
        {
            SynchronizationContext actionDispatcherSyncContext = null;

            using (ManualResetEvent completed = new ManualResetEvent(false))
            using (ManualResetEvent wait = new ManualResetEvent(false))
            using (ActionThread thread1 = new ActionThread())
            using (ActionThread thread2 = new ActionThread())
            {
                thread1.Start();
                thread2.Start();

                // Capture the second thread's SynchronizationContext.
                actionDispatcherSyncContext = thread2.DoGet(() => { return SynchronizationContext.Current; });

                // Have the first thread do a synchronous Send to the second thread and then trigger the "completed" event.
                // The action queued to the second thread will wait for the "wait" event.

                thread1.Do(() =>
                    {
                        actionDispatcherSyncContext.Send((state) => { wait.WaitOne(); }, null);
                        completed.Set();
                    });

                bool completedSignalled = completed.WaitOne(100);
                Assert.IsFalse(completedSignalled, "ActionDispatcherSynchronizationContext.Send is not synchronous");

                wait.Set();
            }
        }
Пример #43
0
 void PodSpawn()
 {
     podInfoThread = UnityThreadHelper.CreateThread((Action)GetRunningPodInfo);
 }
Пример #44
0
 private void BtnEncSC_Click(object sender, System.EventArgs e)
 {
     ActionThread.Start(ScEncrypt);
 }
Пример #45
0
 public void IsAliveProperty_BeforeStart_IsFalse()
 {
     using (ActionThread thread = new ActionThread())
     {
         Assert.IsFalse(thread.IsAlive, "ActionThread is alive before starting");
     }
 }
Пример #46
0
        public void SyncAction_QueuedAfterStart_IsExecutedByThread()
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() => { threadId = Thread.CurrentThread.ManagedThreadId; });

                Assert.AreEqual(thread.ManagedThreadId, threadId, "ActionThread ran in wrong thread context");
            }
        }
Пример #47
0
 public void SyncAction_QueuedBeforeStart_ThrowsThreadStateException()
 {
     using (ActionThread thread = new ActionThread())
     {
         thread.DoSynchronously(() => { });
     }
 }
Пример #48
0
 private void BtnDecCsv_Click(object sender, System.EventArgs e)
 {
     ActionThread.Start(CsvDecrypt);
 }
Пример #49
0
        public void SyncContext_FromInsideAction_IsActionDispatcherSyncContext()
        {
            SynchronizationContext actionThreadSyncContext = null;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();

                // Capture the thread's SynchronizationContext and signal this thread when it's captured.
                actionThreadSyncContext = thread.DoGet(() => { return SynchronizationContext.Current; });

                Assert.IsInstanceOfType(actionThreadSyncContext, typeof(ActionDispatcherSynchronizationContext), "ActionThread did not provide an ActionDispatcherSynchronizationContext");
            }
        }
Пример #50
0
        static public ActionBase Create(string ActionObjectString)
        {
            ActionBase output = null;

            try
            {
                output = Activator.CreateInstance("AutoRobo.Core", "AutoRobo.Core.Actions." + ActionObjectString).Unwrap() as ActionBase;
            }
            catch
            {
                //兼容老版本数据
                switch (ActionObjectString)
                {
                case "BrowserClick": output = new ActionClick(); break;

                case "Navigate": output = new ActionNavigate(); break;

                case "ScriptPart": output = new ActionScriptPart(); break;

                case "AlertHandler": output = new ActionAlertHandler(); break;

                case "ActionDoubleClick": output = new ActionDoubleClick(); break;

                case "ActionFireEvent": output = new ActionFireEvent(); break;

                case "ActionKey": output = new ActionKey(); break;

                case "Mouse": output = new ActionMouse(); break;

                case "RadioButton": output = new ActionRadio(); break;

                case "Checkbox": output = new ActionCheckbox(); break;

                case "SelectList": output = new ActionSelectList(); break;

                case "TypeText": output = new ActionTypeText(); break;

                case "DirectionKey": output = new ActionDirectionKey(); break;

                case "Sleep": output = new ActionSleep(); break;

                case "Wait": output = new ActionWait(); break;

                case "ValidateCode": output = new ActionValidateCode(); break;

                case "FileUpload": output = new ActionFileDialog(); break;

                case "ValidateImage": output = new ActionValidateImage(); break;

                case "JavascriptInterpreter": output = new ActionJavascriptInterpreter(); break;

                case "SubmitClick": output = new ActionSubmitClick(); break;

                case "CloseWindow": output = new ActionCloseWindow(); break;

                case "WindowBack": output = new ActionBack(); break;

                case "WindowForward": output = new ActionForward(); break;

                case "WindowOpen": output = new ActionOpenWindow(); break;

                case "WindowRefresh": output = new ActionRefresh(); break;

                case "SubElementFinder": output = new ActionSubElements(); break;

                case "CallFunction": output = new ActionCall(); break;

                case "ActionForeach": output = new ActionForeach(); break;

                case "ActionBrowser": output = new ActionBrowser(); break;

                case "ActionThread": output = new ActionThread(); break;
                    //case "AddChildrenToList": output = new AddChildrenToList(); break;
                }
            }
            //if (output == null)
            //{
            //    throw new ApplicationException(string.Format("{0}对应的活动未找到", ActionObjectString));
            //}

            return(output);
        }