using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public static class Program
{
[STAThread]
public static void Main()
{
using (var browser = new WebBrowser())
{
browser.Navigate(string.Empty);
browser.Document.InvokeScript("execScript", new object[] { "function set_obj(obj) { window.obj = obj }" });
browser.Document.InvokeScript("execScript", new object[] { "function say_hello() { window.obj.WriteLine('Hello world') }" });
browser.Document.InvokeScript("set_obj", new object[] { new Obj() });
browser.Document.InvokeScript("say_hello");
browser.Document.InvokeScript("setTimeout", new object[] { "say_hello()", 100 });
Console.ReadKey();
}
}
}
[ComVisible(true)]
public sealed class Obj
{
public void WriteLine(string message)
{
Console.WriteLine(message);
}
}
即時呼び出しを起動されません。どうして?回避策はありますか?はなぜWebBrowserコントロールにsetTimeoutメソッドを経由して、スケジュールのコードは正常に動作しますが、私はsetTimeoutをを使用して、それを延期するとき、それが呼び出されていないsay_hello方法の
私もsetTimeoutを引数として文字列の代わりに機能を渡そうとしました - それは助けにはならなかった。 \t browser.Document.InvokeScript(「setTimeoutを」、新しいオブジェクト[ ] {((dynamic)browser.Document.Window.DomWindow).say_hello、100}); –