以下给出 1-2 秒后的结果:
[STAThread]
static void Main()
{
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form1());
Task mainTask = MainAsync();
mainTask.Wait();
}
static async Task MainAsync()
{
var func = Edge.Func(@"
var esprima = require('esprima');
var stringify = require('json-stable-stringify');
var esprimaast = esprima.parse('var a=1;', { loc: true });
var esprimaStr = stringify(esprimaast, { space: 3 });
return function (data, callback) {
callback(null, esprimaStr);
}
");//end Edge.Func
var result = await func(null);
Console.WriteLine(result.ToString());
JavaScriptSerializer serializer = new JavaScriptSerializer();
Object myresult = serializer.Deserialize<JSProgram>(result.ToString());
Console.WriteLine(serializer.Serialize(myresult));
}
但是当我使用 Windows 窗体时
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
并在按钮点击下触发它
private void button1_Click(object sender, EventArgs e)
{
Task mainTask = MainAsync();
mainTask.Wait();
}
async Task MainAsync()
{
var func = Edge.Func(@"
var esprima = require('esprima');
var stringify = require('json-stable-stringify');
var esprimaast = esprima.parse('var a=1;', { loc: true });
var esprimaStr = stringify(esprimaast, { space: 3 });
return function (data, callback) {
callback(null, esprimaStr);
}
");//end of Edge.Func
var result = await func(null);
txtEsprima.Text = result.ToString();
JavaScriptSerializer serializer = new JavaScriptSerializer();
Object myresult = serializer.Deserialize<JSProgram>(result.ToString());
txtMe.Text=serializer.Serialize(myresult);
}
完全没有回复,有什么问题吗?