<div>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).</div>
<div> </div>
<div>Regards,</div>
<div> Raffaele</div>
<div> </div>
<div>
<div><font face="courier new,monospace"> public class TestLoop : ILoadNotificationPlugin</font></div>
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> </font>
<div><font face="courier new,monospace"> Delegate void DoStuffDelegate();</font></div>
<div><font face="courier new,monospace"> </font></div><font face="courier new,monospace"> public void doStuff()</font></div>
<div class="im">
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> EventConsumer con = new EventConsumer("all", "");</font></div></div>
<div><font face="courier new,monospace"> while (true)</font></div>
<div class="im">
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> Event ev = con.pop(0);</font></div></div>
<div><font face="courier new,monospace"> Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);</font></div>
<div><font face="courier new,monospace"> freeswitch.msleep(100);</font></div>
<div><font face="courier new,monospace"> }</font></div>
<div><font face="courier new,monospace"> }</font></div>
<div>
<div><font face="courier new,monospace"> public bool Load()</font></div>
<div class="im">
<div><font face="courier new,monospace"> {</font></div>
<div><font face="courier new,monospace"> DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);</font></div>
<div>
<div><font face="courier new,monospace"> dsdlg.BeginInvoke();</font></div><font face="courier new,monospace"> }</font></div></div><font face="courier new,monospace"> }<br></font><br></div></div>
<div class="gmail_quote">On Tue, Sep 8, 2009 at 08:21, Josh Rivers <span dir="ltr"><<a href="mailto:josh@radianttiger.com">josh@radianttiger.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Thanks for the response!
<div><br></div>
<div>I have tried putting a long-running loop here, but then it blocks anything else managed from happening:</div>
<div><br></div>
<div>
<div> public class TestLoop : ILoadNotificationPlugin</div>
<div> {</div>
<div> public bool Load()</div>
<div class="im">
<div> {</div>
<div> EventConsumer con = new EventConsumer("all", "");</div></div>
<div> while (true)</div>
<div class="im">
<div> {</div>
<div> Event ev = con.pop(0);</div></div>
<div> Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);</div>
<div> freeswitch.msleep(100);</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div><br></div>
<div>However, if I fork off a thread here, freeswitch crashes:</div>
<div>
<div> public class TestLoop : ILoadNotificationPlugin</div>
<div> {</div>
<div> public bool Load()</div>
<div> {</div>
<div> ThreadPool.QueueUserWorkItem((o) =></div>
<div> {</div>
<div> Log.WriteLine(LogLevel.Notice, "Thread Starting. ");</div>
<div class="im">
<div> EventConsumer con = new EventConsumer("all", "");</div></div>
<div> while (true)</div>
<div class="im">
<div> {</div>
<div> Event ev = con.pop(0);</div></div>
<div> Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);</div>
<div> freeswitch.msleep(100);</div>
<div> }</div>
<div> });</div>
<div> return true;</div>
<div> }</div>
<div> }</div>
<div><br></div>
<div>It doesn't look like this is a good place to start a long-running process?</div>
<div><br></div>
<div>Thanks!</div>
<div>Josh</div><font color="#888888">
<div><br></div></font></div></div>
<div>
<div></div>
<div class="h5">
<div>
<div class="gmail_quote">On Mon, Sep 7, 2009 at 11:05 PM, Raffaele P. Guidi <span dir="ltr"><<a href="mailto:raffaele.p.guidi@gmail.com" target="_blank">raffaele.p.guidi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Yes!
<div><br></div>
<div>
<div><font face="'courier new', monospace">public class LoadDemo : ILoadNotificationPlugin {</font></div>
<div><font face="'courier new', monospace"> public bool Load() {</font></div>
<div><font face="'courier new', monospace"> Log.WriteLine(LogLevel.Notice, "LoadDemo running.");</font></div>
<div><font face="'courier new', monospace"> return true;</font></div>
<div><font face="'courier new', monospace"> }</font></div>
<div><font face="'courier new', monospace">}</font></div>
<div><br></div>
<div>this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.</div>
<div><br></div>
<div>And let me add that works like a charm :)</div>
<div><br></div>
<div>Ciao,</div>
<div> Raffaele</div><br>
<div class="gmail_quote">
<div>
<div></div>
<div>On Sun, Sep 6, 2009 at 22:50, Josh Rivers <span dir="ltr"><<a href="mailto:josh@radianttiger.com" target="_blank">josh@radianttiger.com</a>></span> wrote:<br></div></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div></div>
<div>
<div>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?</div>
<div><br></div>
<div><quote author="Phillip Jones"></div>
<div>
<div></div>
<div>
<div>Exactly what I was after - thank you!</div>
<div><br></div>
<div>On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <<a href="mailto:jlenk@frontiernet.net" target="_blank">jlenk@frontiernet.net</a>> wrote:</div>
<div><br></div>
<div>></div>
<div>> try something like this</div>
<div>></div>
<div>> EventConsumer con = new EventConsumer("all", "");</div>
<div>> Event ev = con.pop(0);</div>
<div>></div>
<div>> see lua sample -</div>
<div>> <a href="http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer" target="_blank">http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer</a></div>
<div>></div>
<div>></div>
<div>> Phillip Jones-2 wrote:</div>
<div>> ></div>
<div>> > Hi there,</div>
<div>> ></div>
<div>> > mod_managed exposes EventReceivedFunction such that:</div>
<div>> ></div>
<div>> > Session.EventReceivedFunction = (e) =></div>
<div>> > {</div>
<div>> > Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());</div>
<div>> > return "";</div>
<div>> > };</div>
<div>> ></div>
<div>> > should trap all events to which i subscribe.</div>
<div>> ></div>
<div>> ></div>
<div>> > But how do I subscribe to events? What is the .NET / managed equivalent</div>
<div>> > of:</div>
<div>> ></div>
<div>> > switch_event_bind(const char *id, switch_event_types_t event, const char</div>
<div>> > *subclass_name, switch_event_callback_t callback, void *user_data);</div>
<div>> ></div>
<div>> ></div>
<div>> ></div>
<div>> > Thank you!</div>
<div>> ></div>
<div>> ></div>
<div>> ></div></div></div><br></div></div>_______________________________________________<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><br><br></blockquote></div><br></div><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><br><br></blockquote></div><br></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>