static async void RunJsTaskWithAsyncAwait(ScriptRuntime3 scriptRuntime3) { { // //await // object result1 = await scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 1 + "');return 1;})()", new Dictionary<string, object>()); Console.WriteLine("await result:" + result1); // object result2 = await scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 2 + "');return 2;})()", new Dictionary<string, object>()); Console.WriteLine("await result:" + result2); // object result3 = await scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 3 + "');return 3;})()", new Dictionary<string, object>()); Console.WriteLine("await result:" + result3); // object result4 = await scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 4 + "');return 4;})()", new Dictionary<string, object>()); Console.WriteLine("await result:" + result4); } //---------- { //async ... scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 1 + "');return 1;})()", new Dictionary<string, object>()); // scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 2 + "');return 2;})()", new Dictionary<string, object>()); // scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 3 + "');return 3;})()", new Dictionary<string, object>()); // scriptRuntime3.ExecuteAsync("(function(){LibEspresso.Log('ok" + 4 + "');return 4;})()", new Dictionary<string, object>()); } }
static void Main(string[] args) { Console.WriteLine("test only!"); ScriptRuntime3 scriptRuntime3 = new ScriptRuntime3(); //---------- ////test1: execute from main thread //for (int i = 0; i < 100; ++i) //{ // Dictionary<string, object> scriptPars = new Dictionary<string, object>(); // scriptRuntime3.Execute("LibEspresso.Log('ok" + i + "');", scriptPars, (result) => // { // //when finish or error this will be called // var exception = result as Exception; // if (exception != null) // { // //this is error // } // }); //} //---------- ////test2: execute from thread pool queue //for (int i = 0; i < 100; ++i) //{ // int snapNum = i; // ThreadPool.QueueUserWorkItem(o => // { // Dictionary<string, object> scriptPars = new Dictionary<string, object>(); // scriptRuntime3.Execute("LibEspresso.Log('ok" + snapNum + "');", scriptPars, (result) => // { // //when finish or error this will be called // var exception = result as Exception; // if (exception != null) // { // //this is error // } // }); // }); //} //---------- //test3: async- await RunJsTaskWithAsyncAwait(scriptRuntime3); Console.ReadLine(); }