internal void Suspend() { ScriptJob job = CurrentJob; job.suspended = true; job.signal.Set(); job.signal2.WaitOne(); }
internal void Suspend() { ScriptJob job = CurrentJob; job.suspended = true; job.dispatcherSignal.Set(); job.workerSignal.WaitOne(); }
internal T Invoke <T>(Func <object> func) { ScriptJob job = _executionQueue.Peek(); job.invokedOperation = func; job.signal.Set(); job.signal2.WaitOne(); return((T)job.invokeResult); }
internal T Invoke <T>(Func <T> func) { ScriptJob job = _executionQueue.Peek(); job.invokedOperation = func; job.dispatcherSignal.Set(); job.workerSignal.WaitOne(); return((T)job.invokeResult); }
internal void Invoke(Action action) { ScriptJob job = CurrentJob; job.invokedOperation = () => { action(); return(null); }; job.signal.Set(); job.signal2.WaitOne(); }
private void StartExecution(ScriptSource src, ScriptScope scope, Action <ExecutionResult> continuation) { var job = new ScriptJob { source = src, scope = scope, continuation = continuation }; _executionQueue.Enqueue(job); if (_executionQueue.Count == 1) // Other scripts may be hung. Scripts are executed in order. { ProcessExecutionQueue(); } }
internal void Invoke(Action action) { ScriptJob job = CurrentJob; job.invokedOperation = action; //job.invokedOperation = () => // { // action(); // return null; // }; job.dispatcherSignal.Set(); job.workerSignal.WaitOne(); }
private void ProcessExecutionQueue() { do { ScriptJob job = _executionQueue.Peek(); Program.GameMess.GameDebug(job.source.GetCode()); // Because some scripts have to be suspended during asynchronous operations (e.g. shuffle, reveal or random), // their evaluation is done on another thread. // The process still looks synchronous (no concurrency is allowed when manipulating the game model), // which is why a ManualResetEvent is used to synchronise the work of both threads if (job.suspended) { job.suspended = false; job.workerSignal.Set(); } else { job.dispatcherSignal = new AutoResetEvent(false); job.workerSignal = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(Execute, job); } job.dispatcherSignal.WaitOne(); while (job.invokedOperation != null) { using (new Mute(job.muted)) job.invokeResult = job.invokedOperation.DynamicInvoke(); job.invokedOperation = null; job.workerSignal.Set(); job.dispatcherSignal.WaitOne(); } if (job.result != null && !String.IsNullOrWhiteSpace(job.result.Error)) { Program.GameMess.Warning("{0}", job.result.Error.Trim()); } if (job.suspended) { return; } job.dispatcherSignal.Dispose(); job.workerSignal.Dispose(); _executionQueue.Dequeue(); if (job.continuation != null) { job.continuation(job.result); } } while (_executionQueue.Count > 0); }
public void Mute(bool muted) { ScriptJob job = _engine.CurrentJob; _engine.CurrentJob.muted = muted ? job.id : 0; }
private void StartExecution(ScriptSource src, ScriptScope scope, Action <ExecutionResult> continuation) { var job = new ScriptJob(src, scope, continuation); StartExecution(job); }