对于以下代码(使用EdgeJS模块),我想等待异步方法Start
完成后再写sw.Elapsed
,我该怎么做?
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using EdgeJs;
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
///
[STAThread]
static void Main()
{
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form1());
Stopwatch sw =new Stopwatch();
sw.Start();
Task.Run((Action)Start).Wait();
//wait for start to complete --- how should I do it??
sw.Stop();
Console.WriteLine(sw.Elapsed);
}
public static async void Start()
{
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, 'Node.js welcomes ' + esprimaStr);
}
");
Console.WriteLine(await func(".NET"));
//Console.WriteLine("hello");
}
}