コード例 #1
0
        public static Task <NKScriptContext> createContext(Dictionary <string, object> options = null)
        {
            syncContext = new SingleThreadSynchronizationContext();

            Task.Factory.StartNew(() => { syncContext.RunOnCurrentThread(); }, TaskCreationOptions.LongRunning);
            var oldSyncContext = SynchronizationContext.Current;

            SynchronizationContext.SetSynchronizationContext(syncContext);
            var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(oldSyncContext);

            syncContext.Post((s) => { }, null);

            return(Task.Factory.StartNew(() =>
            {
                if (options == null)
                {
                    options = new Dictionary <string, object>();
                }

                if (!runtimeCreated)
                {
                    runtime = JavaScriptRuntime.Create(JavaScriptRuntimeAttributes.None, JavaScriptRuntimeVersion.VersionEdge, null);
                    runtimeCreated = true;
                }

                var chakra = runtime.CreateContext();
                int id = NKScriptContextFactory.sequenceNumber++;
                var context = new NKSChakraContext(id, chakra, options);

                var item = new Dictionary <String, object>();
                NKScriptContextFactory._contexts[id] = item;
                item["JSVirtualMachine"] = runtime;   // if future non-shared runtimes required;
                item["context"] = context;

                return context.completeInitialization();
            }, Task.Factory.CancellationToken, TaskCreationOptions.LongRunning, taskScheduler).Unwrap());
        }
コード例 #2
0
        public static Task<NKScriptContext> createContext(Dictionary<string, object> options = null)
        {

            syncContext = new SingleThreadSynchronizationContext();

            Task.Factory.StartNew(() => { syncContext.RunOnCurrentThread(); }, TaskCreationOptions.LongRunning);
            var oldSyncContext = SynchronizationContext.Current;
            SynchronizationContext.SetSynchronizationContext(syncContext);
            var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(oldSyncContext);

            syncContext.Post((s) => { }, null);

            return Task.Factory.StartNew(() =>
             {
                 if (options == null)
                     options = new Dictionary<string, object>();

                 if (!runtimeCreated)
                 {
                     runtime = JavaScriptRuntime.Create(JavaScriptRuntimeAttributes.None, JavaScriptRuntimeVersion.VersionEdge, null);
                     runtimeCreated = true;
                 }

                 var chakra = runtime.CreateContext();
                 int id = NKScriptContextFactory.sequenceNumber++;
                 var context = new NKSChakraContext(id, chakra, options);

                 var item = new Dictionary<String, object>();
                 NKScriptContextFactory._contexts[id] = item;
                 item["JSVirtualMachine"] = runtime;  // if future non-shared runtimes required;
                 item["context"] = context;

                 return context.completeInitialization();
             }, Task.Factory.CancellationToken, TaskCreationOptions.LongRunning, taskScheduler).Unwrap();
        }
コード例 #3
0
 internal NKSChakraScriptDelegate(NKSChakraContext context)
 {
     this.context = context;
 }