Exemplo n.º 1
0
        public static bool Suspend(WaitHandle handle, int milliseconds)
        {
            RuntimeExecution current = EnsureInstance();

            current.AwakeParentThread();
            return(handle.WaitOne(milliseconds));
        }
Exemplo n.º 2
0
        public static RuntimeExecution CreateWorkerThread(RuntimeExecutionStart action, bool autoExit)
        {
            ManualResetEvent waitHandle  = new ManualResetEvent(false);
            RuntimeRealm     parentRealm = RuntimeRealm.Current;
            RuntimeExecution execution   = null;
            Thread           thread      = new Thread(() => {
                execution = EnsureInstance();
                execution.parentWaitHandle = waitHandle;
                execution.AutoExit         = autoExit;
                try {
                    action(parentRealm);
                    execution.AwakeParentThread();
                    ContinueUntilEnd();
                } catch (Exception ex) {
                    SendUnhandledException(ex);
                    execution.AwakeParentThread();
                }
            });

            thread.IsBackground = true;
            thread.Start();
            waitHandle.WaitOne();
            return(execution);
        }