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:
And then:
Cheers!
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)); })); } }
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); }); ");