-
Notifications
You must be signed in to change notification settings - Fork 158
Closed
Labels
Description
Hello,
i have the following code:
internal class Program
{
static void Main(string[] args)
{
//Promise Task conversion
using (V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableTaskPromiseConversion))
{
engine.AddHostType("TestClass", typeof(TestClass));
engine.Evaluate(
"""
TestClass.executeScriptAction( async (x) =>
{
return x.toLowerCase();
}
);
"""
);
}
}
}
public static class TestClass
{
public static void executeScriptAction(IJavaScriptObject obj)
{
//returns Task with Status -> TaskStatus.WaitingForActivation
object result = obj.InvokeAsFunction("TestText");
if (result is Task<object> resultAsTask)
{
//Waits forever here
result = resultAsTask.GetAwaiter().GetResult();
}
Console.WriteLine(result);
}
}
If i run this example the Promise
from js is converted into a Task
with the status WaitingForActivation
and the code is waiting infinite for the Task
to finish.
How could i receive the result of the js-function?
.csproj-File
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ClearScript" Version="7.4.5" />
</ItemGroup>
</Project>
With kind regards,
David