Well, I can't see any delegate in josh sample, just a <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(68, 68, 68); ">ThreadPool.QueueUserWorkItem. </span>Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.<div>
<br></div><div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">public class LoadPluginDemo : ILoadNotificationPlugin {</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">delegate void Listener();</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">private void EventListener() {</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> EventConsumer con = new EventConsumer("all", null);</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> while (true){</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace"> Event ev = con.pop(1);</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace"> Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> }</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">                </font></span><font class="Apple-style-span" face="'courier new', monospace">}</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> public bool Load() {</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> Log.WriteLine(LogLevel.Notice, "LoadDemo running.");</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> new Listener(EventListener).BeginInvoke(null,null);</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> return true;</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace"> }</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">}</font></div>
<div><br></div><div><br></div><br><div class="gmail_quote">On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <span dir="ltr"><<a href="mailto:mgg@giagnocavo.net">mgg@giagnocavo.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p><span style="font-size:11.0pt;color:#1F497D">That’s what his sample does, but he says it crashes.</span></p>
<p><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p><b><span style="font-size:10.0pt">From:</span></b><span style="font-size:10.0pt">
<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>
[mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>On Behalf Of </b>Raffaele
P. Guidi<br>
<b>Sent:</b> Tuesday, September 08, 2009 10:08 AM</span></p><div class="im"><br>
<b>To:</b> <a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank">freeswitch-users@lists.freeswitch.org</a><br>
<b>Subject:</b> Re: [Freeswitch-users] Subscribing to events in managed C# /
.NET</div><p></p>
</div>
<p> </p>
<div>
<p>Hi, you just have to use delegates to asynchronously call
the function containing the loop and return back the control to the calling
thread. Here an example (don't have my code at hand, hope it doesn't contain
typos).</p>
</div><div><div></div><div class="h5">
<div>
<p> </p>
</div>
<div>
<p>Regards,</p>
</div>
<div>
<p> Raffaele</p>
</div>
<div>
<p> </p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New""> public
class TestLoop : ILoadNotificationPlugin</span></p>
</div>
<div>
<p><span style="font-family:"Courier New""> {</span></p>
</div>
<div>
<p><span style="font-family:"Courier New""> </span></p>
<div>
<p><span style="font-family:"Courier New""> Delegate
void DoStuffDelegate();</span></p>
</div>
<div>
<p><span style="font-family:"Courier New""> </span></p>
</div>
<p><span style="font-family:"Courier New""> public
void doStuff()</span></p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New"">
{</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
EventConsumer con = new
EventConsumer("all", "");</span></p>
</div>
</div>
<div>
<p><span style="font-family:"Courier New"">
while (true)</span></p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New"">
{</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
Event ev = con.pop(0);</span></p>
</div>
</div>
<div>
<p><span style="font-family:"Courier New"">
Log.WriteLine(LogLevel.Notice,
"Event: " + ev.serialized_string);</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
freeswitch.msleep(100);</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
}</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
}</span></p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New""> public
bool Load()</span></p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New"">
{</span></p>
</div>
<div>
<p><span style="font-family:"Courier New""> DoStuffDelegate
dsdlg = new DoStuffDelegate(doStuff);</span></p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New""> dsdlg.BeginInvoke();</span></p>
</div>
<p><span style="font-family:"Courier New""> }</span></p>
</div>
</div>
<p style="margin-bottom:12.0pt"><span style="font-family:"Courier New""> }</span></p>
</div>
</div>
<div>
<p>On Tue, Sep 8, 2009 at 08:21, Josh Rivers <<a href="mailto:josh@radianttiger.com" target="_blank">josh@radianttiger.com</a>> wrote:</p>
<p>Thanks for the response! </p>
<div>
<p> </p>
</div>
<div>
<p>I have tried putting a long-running loop here, but then it
blocks anything else managed from happening:</p>
</div>
<div>
<p> </p>
</div>
<div>
<div>
<p> public class TestLoop : ILoadNotificationPlugin</p>
</div>
<div>
<p> {</p>
</div>
<div>
<p> public bool Load()</p>
</div>
<div>
<div>
<p> {</p>
</div>
<div>
<p> EventConsumer
con = new EventConsumer("all", "");</p>
</div>
</div>
<div>
<p> while (true)</p>
</div>
<div>
<div>
<p> {</p>
</div>
<div>
<p>
Event ev = con.pop(0);</p>
</div>
</div>
<div>
<p>
Log.WriteLine(LogLevel.Notice, "Event: " +
ev.serialized_string);</p>
</div>
<div>
<p>
freeswitch.msleep(100);</p>
</div>
<div>
<p> }</p>
</div>
<div>
<p> }</p>
</div>
<div>
<p> }</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>However, if I fork off a thread here, freeswitch crashes:</p>
</div>
<div>
<div>
<p> public class TestLoop :
ILoadNotificationPlugin</p>
</div>
<div>
<p> {</p>
</div>
<div>
<p> public bool Load()</p>
</div>
<div>
<p> {</p>
</div>
<div>
<p>
ThreadPool.QueueUserWorkItem((o) =></p>
</div>
<div>
<p> {</p>
</div>
<div>
<p>
Log.WriteLine(LogLevel.Notice, "Thread Starting. ");</p>
</div>
<div>
<div>
<p>
EventConsumer con = new EventConsumer("all", "");</p>
</div>
</div>
<div>
<p>
while (true)</p>
</div>
<div>
<div>
<p>
{</p>
</div>
<div>
<p>
Event ev = con.pop(0);</p>
</div>
</div>
<div>
<p>
Log.WriteLine(LogLevel.Notice, "Event: " +
ev.serialized_string);</p>
</div>
<div>
<p>
freeswitch.msleep(100);</p>
</div>
<div>
<p>
}</p>
</div>
<div>
<p> });</p>
</div>
<div>
<p> return true;</p>
</div>
<div>
<p> }</p>
</div>
<div>
<p> }</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>It doesn't look like this is a good place to start a
long-running process?</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>Thanks!</p>
</div>
<div>
<p>Josh</p>
</div>
<div>
<p><span style="color:#888888"> </span></p>
</div>
</div>
</div>
<div>
<div>
<div>
<div>
<p>On Mon, Sep 7, 2009 at 11:05 PM, Raffaele P. Guidi <<a href="mailto:raffaele.p.guidi@gmail.com" target="_blank">raffaele.p.guidi@gmail.com</a>>
wrote:</p>
<p>Yes! </p>
<div>
<p> </p>
</div>
<div>
<div>
<p><span style="font-family:"Courier New"">public class
LoadDemo : ILoadNotificationPlugin {</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
public bool Load() {</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">
return true;</span></p>
</div>
<div>
<p><span style="font-family:"Courier New""> }</span></p>
</div>
<div>
<p><span style="font-family:"Courier New"">}</span></p>
</div>
<div>
<p> </p>
</div>
<div>
<p>this example is from Michael Giagnocavo's Demo.csx which you
can find into the mod_managed svn.</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>And let me add that works like a charm :)</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>Ciao,</p>
</div>
<div>
<p> Raffaele</p>
</div>
<p> </p>
<div>
<div>
<div>
<p>On Sun, Sep 6, 2009 at 22:50, Josh Rivers <<a href="mailto:josh@radianttiger.com" target="_blank">josh@radianttiger.com</a>>
wrote:</p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p>Is there a way to start this when FreeSWITCH starts? The lua
and perl modules have a 'startup-script' configuration preference. Is there
something similar in mod_managed? Or is there a way to have an api command
executed at a startup?</p>
</div>
<div>
<p> </p>
</div>
<div>
<p><quote author="Phillip Jones"></p>
</div>
<div>
<div>
<div>
<p>Exactly what I was after - thank you!</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <<a href="mailto:jlenk@frontiernet.net" target="_blank">jlenk@frontiernet.net</a>>
wrote:</p>
</div>
<div>
<p> </p>
</div>
<div>
<p>> </p>
</div>
<div>
<p>> try something like this</p>
</div>
<div>
<p>> </p>
</div>
<div>
<p>> EventConsumer con = new EventConsumer("all",
"");</p>
</div>
<div>
<p>> Event ev = con.pop(0);</p>
</div>
<div>
<p>> </p>
</div>
<div>
<p>> see lua sample -</p>
</div>
<div>
<p>> <a href="http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer" target="_blank">http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer</a></p>
</div>
<div>
<p>> </p>
</div>
<div>
<p>> </p>
</div>
<div>
<p>> Phillip Jones-2 wrote:</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > Hi there,</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > mod_managed exposes EventReceivedFunction such
that:</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > Session.EventReceivedFunction = (e) =></p>
</div>
<div>
<p>> > {</p>
</div>
<div>
<p>> > Log.WriteLine(LogLevel.Alert,
"Received Event {0}", e.ToString());</p>
</div>
<div>
<p>> > return "";</p>
</div>
<div>
<p>> > };</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > should trap all events to which i subscribe.</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > But how do I subscribe to events? What is the .NET
/ managed equivalent</p>
</div>
<div>
<p>> > of:</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > switch_event_bind(const char *id,
switch_event_types_t event, const char</p>
</div>
<div>
<p>> > *subclass_name, switch_event_callback_t callback,
void *user_data);</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> > Thank you!</p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> ></p>
</div>
<div>
<p>> ></p>
</div>
</div>
</div>
<p> </p>
</div>
</div>
<p style="margin-bottom:12.0pt">_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a></p>
</blockquote>
</div>
<p> </p>
</div>
<p style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a></p>
</div>
<p> </p>
</div>
</div>
</div>
<p style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org</a></p>
</div>
<p> </p>
</div></div></div>
</div>
<br>_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br></div>