在 Awesomium-sharp 中,我编写了这样的 C# 代码:
WebControl webControl = new WebControl();
webControl.CreateObject("external");
SetObjectCallback("external", "JSCallback", OnJSCallback);
private int count = 0;
private void OnJSCallback(object sender, JSCallbackEventArgs e)
{
Console.WriteLine("hi");
MessageBox.Show("hi");
if (count == 0)
{
Thread worker = new Thread(func =>
{
Thread.Sleep(3000);
OnReturn();
});
worker.Start();
}
if (count == 1)
{
Thread worker = new Thread(func =>
{
Thread.Sleep(5000);
OnReturn();
});
worker.Start();
}
count++;
}
private void OnReturn()
{
webControl.Dispatcher.BeginInvoke((ThreadStart) delegate()
{
webControl.CallJavascriptFunction("", "CallFromNative", new JSValue[] {new JSValue("hello")});
});
}
和javascript代码是这样的:
external.JSCallback("hello ", "world");
external.JSCallback("wtf ", "dude");
奇怪的问题是,来自 Javascript 的第二次调用似乎被忽视并且从未执行过。我的代码有什么问题?顺便说一句,AwesomiumSharp 的版本是 V1.6.6