1

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 Answer 1

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:

Edge

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.