Using Edge.js from a C# console application

删除回忆录丶 提交于 2019-12-11 11:34:41

问题


I'm trying to do something that seems very simple, yet I cannot get it to work. I've installed Edge.js via nuget and I want to execute a piece of Javascript from inside a C# console application. The code from my public static void main is below:

Task.Run(async () => {
    Console.WriteLine(
        await Edge.Func("return function() { return 'hello world'; }")(null).Result
    );
}).Wait();

I run the application and all it does is hangs.

I've tried this:

Console.WriteLine(Edge.Func("return function() { return 'hello'; }")(null).Result);

Same result. And this too...

var task = Edge.Func("return function() { return 'hello'; }")(null);
await task;
Console.WriteLine(task.Result);

Same result. Hanging...

I also tried RunSynchronously() rather than awaiting, which gave me an InvalidOperationException.

I followed the documentation here.

Any ideas?


回答1:


You have to use the callback to send the string. You can't just return the string. See:

Edge.Func(@"
        return function (data, callback) {
            callback(null, 'hello world');
        }
    ");

You have to follow this structure when using Edge:



来源:https://stackoverflow.com/questions/31190524/using-edge-js-from-a-c-sharp-console-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!