Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#控制台应用程序使用Edge.js_C#_Node.js_Edge.js - Fatal编程技术网

从C#控制台应用程序使用Edge.js

从C#控制台应用程序使用Edge.js,c#,node.js,edge.js,C#,Node.js,Edge.js,我试图做一些看起来很简单的事情,但我无法让它工作。我已经通过nuget安装了Edge.js,我想在C#console应用程序中执行一段Javascript。mypublic static void main中的代码如下: Task.Run(async () => { Console.WriteLine( await Edge.Func("return function() { return 'hello world'; }")(null).Result );

我试图做一些看起来很简单的事情,但我无法让它工作。我已经通过nuget安装了Edge.js,我想在C#console应用程序中执行一段Javascript。my
public static void main
中的代码如下:

Task.Run(async () => {
    Console.WriteLine(
        await Edge.Func("return function() { return 'hello world'; }")(null).Result
    );
}).Wait();
我运行应用程序,它所做的只是挂起

我试过这个:

Console.WriteLine(Edge.Func("return function() { return 'hello'; }")(null).Result);
同样的结果。还有这个

var task = Edge.Func("return function() { return 'hello'; }")(null);
await task;
Console.WriteLine(task.Result);
同样的结果。吊死

我还尝试了
RunSynchronously()
而不是等待,这给了我一个
invalidoOperationException

我遵循文档


有什么想法吗?

您必须使用回调发送字符串。你不能只返回字符串。见:

Edge.Func(@"
        return function (data, callback) {
            callback(null, 'hello world');
        }
    ");
使用Edge时,必须遵循以下结构: