0

I am using cefsharp.Wpf and I need to run 2 commands togheter.

This is the object I am binding to my javascript

public class CefSharpCommonObject
{
    public dynamic Start()
    {
        var response = dummyProc.Start();

        return new
        {
            response.IsSuccess
        };
    }

    public dynamic Stop()
    {
        var response = dummyProc.Stop();

        return new
        {
            response.IsSuccess
        };
    }
}

Like the following:

cefBrowser.JavascriptObjectRepository.Register("jsCommunicator", new CefSharpCommonObject(), true);

I call the start method using:

<script type="text/javascript">
    (async () => {
        await CefSharp.BindObjectAsync("jsCommunicator", "jsTest");

        jsCommunicator.start().then(() => {}, () => {});

        setTimeout(jsCommunicator.stop, 5000);
    })();
</script>

The start method uses a while loop that checks something and then sleeps for 1 second and I fear it may be blocking the UI thread because the stop method isn't being called. Only after the start method auto exits after like 30 seconds.

Is there a way I can make the start method a task so I can run it in another thread and still get the return value after it stops?

smn.tino
  • 2,272
  • 4
  • 32
  • 41
Or Betzalel
  • 2,427
  • 11
  • 47
  • 70
  • You can use a call back see https://github.com/cefsharp/CefSharp/blob/cefsharp/63/CefSharp.Example/BoundObject.cs#L59 – amaitland Jun 23 '18 at 00:30
  • Support for returning `Task` has been added in https://github.com/cefsharp/CefSharp/issues/2758 – amaitland Jun 08 '19 at 08:05

0 Answers0