Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Debugging hangs if an event handler for a UI element is set and event handler gets executed (V8)

0
0
Hi ahmetuzun,

Thanks for posting your solution! Here's an alternative that uses only public APIs and supports all events that follow the standard pattern:
publicstaticclass EventSourceExtensions {
    publicstatic EventConnection<T> connectAsync<T>(this EventSource<T> source, object callback) {
        return source.connect(new EventHandler((sender, args) => {
            ThreadPool.QueueUserWorkItem(_ => ((dynamic)callback)(sender, args));
        }));
    }
}
And then:
engine.AddHostType(typeof(Console));
engine.AddHostType(typeof(EventSourceExtensions));
engine.Execute(@"
    var connect1 = main.SizeChanged.connectAsync(function (sender, e) {
        Console.WriteLine('SizeChanged');
    });
    var connect2 = main.MouseClick.connectAsync(function (sender, e) {
        Console.WriteLine('MouseClick({0}, {1})', e.X, e.Y);
    });
");
Cheers!

Viewing all articles
Browse latest Browse all 2297