1

I've recently ran into some problems while trying to run a Node function, when trying to run the code below, my program just freezes.

{
    class Interpreter
    {
        public static async Task NodeFunc()
        {
            var func = Edge.Func(@"
            return function (data, callback) {
                callback(null, 'Node.js welcomes ' + data);
            }
        ");

            Console.WriteLine(await func(".NET"));
        }

        public static void chamar()
        {
            NodeFunc().Wait();
        }
    }
}

I've confirmed that the program only freezes when the await is executed, so that's the root of the problem, I'm probably "waiting" infinitely.

The only thing I receive in the debug console is the following:

The thread 0x41f8 has exited with code 0 (0x0).
The thread 0x52a0 has exited with code 0 (0x0).

Which I have no idea what it means, any help?

Spyro
  • 11
  • 1
  • Operations that block the current thread, such as `Task.Result` and `Task.Wait()`, often lead to deadlock, just as in your example. See duplicate. When your code calls `chamar()`, which then in turn calls `NodeFunc()`, that has the effect of blocking the thread in the `chamar()` method, preventing it from being available to resume execution after the `await` in the `NodeFunc()` method. The right way to fix it is to make `chamar()` an `async` method and `await` it, make its caller `async` and `await` it, and so on, until the entire thread is handling things asynchronously. – Peter Duniho Jul 02 '21 at 00:01
  • As far as the thread-exited messages go, those are normal and not directly related to the issue you're having. – Peter Duniho Jul 02 '21 at 00:02

0 Answers0