<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On
Behalf Of </b>Matthew Barnard<br>
<b>Sent:</b> Tuesday, May 13, 2008 5:39 PM<br>
<b>To:</b> IronPython List<br>
<b>Subject:</b> [IronPython] System.Windows.Forms.MethodInvoker<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>The C# sample runs as expected, displaying 'Started.
Finished.', but the ipy does nothing.<br>
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,<br>
but I'm honestly lost.<br>
<br>
<span style='color:#3333FF'>C#:<br>
<br>
class foo<br>
{<br>
public void start()<br>
{<br>
Console.WriteLine("Started.");<br>
Thread.Sleep(2000);<br>
}<br>
<br>
public void finish(IAsyncResult r)<br>
{<br>
Console.WriteLine("Finished.");<br>
}<br>
}<br>
<br>
class Program<br>
{<br>
static void Main(string[] args)<br>
{<br>
foo bar = new foo();<br>
<br>
MethodInvoker mi = new
MethodInvoker(bar.start);<br>
mi.BeginInvoke(new
AsyncCallback(bar.finish), null);<br>
<br>
Console.ReadLine();<br>
}<br>
}</span><br>
<br>
<br>
<span style='color:#009900'>IPY:<br>
<br>
import clr<br>
<br>
clr.AddReferenceByPartialName('System.Windows.Forms')<br>
<br>
from System import AsyncCallback<br>
from System.Threading import Thread<br>
from System.Windows.Forms import MethodInvoker<br>
<br>
class foo:<br>
def start(self):<br>
print 'Started.'<br>
Thread.Sleep(2000)<br>
<br>
def finish(self, r):<br>
print 'Finished.'<br>
<br>
bar = foo()<br>
mi = MethodInvoker(bar.start)<br>
mi.BeginInvoke(AsyncCallback(bar.finish), None)<br>
</span><br>
<br>
___________________________<br>
Matthew Barnard<o:p></o:p></p>
</div>
</body>
</html>