Surely this is because you are calling ev.serialized_string and ev is null if there is not event waiting?<div><br></div><div>i.e. con.pop(0); returns null if no event is waiting.</div><div><br></div><div>Therefore</div><div>
<br></div><div>if(ev != null)</div><div> Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);<br><br></div><div>would work, alternatively calling </div><div><br></div><div><div class="im"><div>
Event ev = con.pop(1);</div><div><br></div><div>would block until an event is available - and therefore ev cannot be null....</div><div><br></div></div></div><div><br></div><div><br><div class="gmail_quote">
On Wed, Sep 9, 2009 at 2:01 PM, Josh Rivers <span dir="ltr"><<a href="mailto:josh@radianttiger.com">josh@radianttiger.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
A new discovery:<div><div class="im"><div> public bool Load()</div><div> {</div><div> ThreadPool.QueueUserWorkItem((o) =></div><div> {</div><div> Log.WriteLine(LogLevel.Notice, "Thread Starting. ");</div>
<div> EventConsumer con = new EventConsumer("all", "");</div><div> while (true)</div><div> {</div><div> Event ev = con.pop(0);</div></div>
<div>
if (ev == null) continue;</div><div class="im"><div> Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);</div><div> }</div></div><div> });</div>
<div> return true;</div>
<div> }</div><div>Does not crash. (Adding the null check prevents crash.) The backgrounded loop runs fine. Looks like the event object goes straight to pinvokes, so a null result just crashes?</div><div><br></div>
<div>
I like the idea of a 'startup-script' for mod_managed. It would also be excellent if there was an event or message informing the background code to terminate nicely when the module reloads.</div><div><br></div><font color="#888888"><div>
--Josh</div></font><div><div></div><div class="h5"><br><div class="gmail_quote">On Wed, Sep 9, 2009 at 12:57 PM, Jeff Lenk <span dir="ltr"><<a href="mailto:jlenk@frontiernet.net" target="_blank">jlenk@frontiernet.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I think the problem here is that the loader only keeps this method in scope<br>
until completion then it drops the remoted connection. Therefore you should<br>
not use threads in this method. Michael please correct me if I am wrong<br>
here.<br>
<br>
As an example of the failure simply just put a Sleep(10000) call in the<br>
thread and you will see the failure.<br>
<br>
As Michael said this method was only designed to allow the option to opt out<br>
of being loaded.<br>
<br>
In order to support this perhaps a configuration flag simular to the lua<br>
"startup-script" should be added.<br>
<div><br>
<br>
<br>
Here is the error I get with the loop I mentioned. -Josh<br>
[image: Capture.PNG]<br>
<br>
On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo<br>
<<a href="mailto:mgg@giagnocavo.net" target="_blank">mgg@giagnocavo.net</a>>wrote:<br>
<br>
> Hi,<br>
><br>
><br>
><br>
> Can you please elaborate on the crash you receive when you<br>
> queue a thread during load?<br>
><br>
><br>
><br>
> Thanks,<br>
><br>
> Michael<br>
><br>
><br>
<br>
</div><font color="#888888">--<br>
View this message in context: <a href="http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html" target="_blank">http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html</a><br>
Sent from the freeswitch-users mailing list archive at Nabble.com.<br>
</font><div><div></div><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>
</div></div></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></div>