[IronPython] System.Windows.Forms.MethodInvoker

Dino Viehland dinov at exchange.microsoft.com
Wed May 14 04:05:20 CEST 2008


Where'd the call to Console.ReadLine go?  That's the reason you don't see Finished printing...  On 1.1 and 2.0B2 from the console or in a file w/ a call to Console.ReadLine or raw_input I end up seeing finished getting printed.  We're simply exiting before the asynchronous operation but that doesn't fully answer the question - started is still never printing!  Stranger yet you can call mi() directly showing the delegate is clearly created correctly and working.  Anyway, I'll have to look at it closer - it might require windbg to figure out what's going wrong here.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Matthew Barnard
Sent: Tuesday, May 13, 2008 5:39 PM
To: IronPython List
Subject: [IronPython] System.Windows.Forms.MethodInvoker

The C# sample runs as expected, displaying 'Started. Finished.', but the ipy does nothing.
Can someone enlighten me as to the difference? I assume it is something to do with the way functions are represented in ipy vs. what methodinvoker is looking for,
but I'm honestly lost.

C#:

class foo
    {
        public void start()
        {
            Console.WriteLine("Started.");
            Thread.Sleep(2000);
        }

        public void finish(IAsyncResult r)
        {
            Console.WriteLine("Finished.");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            foo bar = new foo();

            MethodInvoker mi = new MethodInvoker(bar.start);
            mi.BeginInvoke(new AsyncCallback(bar.finish), null);

            Console.ReadLine();
        }
    }


IPY:

import clr

clr.AddReferenceByPartialName('System.Windows.Forms')

from System import AsyncCallback
from System.Threading import Thread
from System.Windows.Forms import MethodInvoker

class foo:
    def start(self):
        print 'Started.'
        Thread.Sleep(2000)

    def finish(self, r):
        print 'Finished.'

bar = foo()
mi = MethodInvoker(bar.start)
mi.BeginInvoke(AsyncCallback(bar.finish), None)


___________________________
Matthew Barnard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080513/2455e8ce/attachment.html>


More information about the Ironpython-users mailing list