[IronPython] IronPython and C# asynchronous events

McCalment, Noah Noah.McCalment at mts.com
Tue Oct 23 18:42:07 CEST 2007

I've been having some trouble connecting IronPython to events in C#.
The issue is illustrated in the short test class and test script
attached to this email.  Specifically, the problem is this: When an
external event is raised to this C# class, the event handler calls a
function which iterates through the list of subscribers.  When these
subscribers are invoked synchronously, there is no issue; everything
works fine.  However, if the subscribers are invoked asynchronously,
IronPython methods cannot be directly added to the subscriber list.  An
ArgumentNullException exception is thrown inside the .Net runtime
library, somewhere in the bowels of the remoting subsystem.  My
questions are these: 1) Is it possible to make asynchronous events "just
work", i.e. allow IronPython scripts to simply call += on an event
member in a C# class and have the subscriber fire whether it is
synchronous or asynchronous?  2) I have found a workaround that involves
using reflection to retrieve a MethodInfo object that gets passed to
Delegate.CreateDelegate().  However, this requires me to dynamically
compile a C# helper class to handle events, because I cannot find a way
to retrieve a MethodInfo for a stock IronPython method.  Is this
possible, and if so, how?

Thanks for your time,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestEvents.py
Type: application/octet-stream
Size: 259 bytes
Desc: TestEvents.py
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20071023/dc1e3d8e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Class1.cs
Type: application/octet-stream
Size: 1358 bytes
Desc: Class1.cs
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20071023/dc1e3d8e/attachment-0001.obj>

More information about the Ironpython-users mailing list