<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<style>BODY{font:10pt Tahoma, Verdana, sans-serif}</style></head><body>
<DIV>The reason it's a public is you may need to decrement it outside of the class, like from API, in a hangup_hook or other place. </DIV>
<DIV>&nbsp;</DIV>
<DIV>--Dave</DIV><BR>
<BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<HR>
<B>From:</B> Malay Thakershi [mailto:mthakershi@gmail.com]<BR><B>To:</B> FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org]<BR><B>Sent:</B> Wed, 06 Mar 2013 19:57:09 -0800<BR><B>Subject:</B> Re: [Freeswitch-users] .NET managed code - call count<BR><BR>I implemented "public static" option for now. I will let you know what happens.
<DIV><BR></DIV>
<DIV>But even "private static" option I had was also sharing call counts across different calls. I am not sure whether logic is buggy or not.</DIV>
<DIV><BR></DIV>
<DIV>I -- the variable in hangup hook function. Is that OK?</DIV>
<DIV><BR></DIV>
<DIV>Thanks.<BR><BR>
<DIV class=gmail_quote>On Wed, Mar 6, 2013 at 9:01 PM, Dave R. Kompel <SPAN>&lt;<A href="mailto:drk@drkngs.net">drk@drkngs.net</A>&gt;</SPAN> wrote:<BR>
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote><U></U>
<DIV>
<DIV>There is not any one specific method of keeping a call count in a managed module that is correct. It all depends on what you are doing in the code.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Using a private is normally a bad idea since if you are doing this from an IAppPlugin interface, and you transfer the call, that instance will go away, and you will never decrement it.</DIV>
<DIV>&nbsp;</DIV>
<DIV>If every call is going through this app, then I would use a public static int, put the whole thing in a try-catch-finally block and decrement the count in the finnaly block, to make sure it executes.</DIV>
<DIV>&nbsp;</DIV>
<DIV>If there is a more complex where the call will get out of your code and still be up then use a static Hashtable&lt;Guid&gt;, and put the sessions uuid in the hash, and have ether an event consumer loop for a channel_hangup_complete remove it, the count of the hashtable should always be right, or have an API in the same module IApiPlugin, that you call to remove the uuid and set the channels API_HANGUP_HOOK so it gets called whenever the channel goes away.</DIV>
<DIV>&nbsp;</DIV>
<DIV>--Dave</DIV><BR>
<BLOCKQUOTE style="BORDER-LEFT: #0000ff 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<HR>
<B>From:</B> Malay Thakershi [mailto:<A href="mailto:mthakershi@gmail.com">mthakershi@gmail.com</A>]<BR><B>To:</B> FreeSWITCH Users Help [mailto:<A href="mailto:freeswitch-users@lists.freeswitch.org">freeswitch-users@lists.freeswitch.org</A>]<BR><B>Sent:</B> Wed, 06 Mar 2013 11:53:13 -0800<BR><B>Subject:</B> [Freeswitch-users] .NET managed code - call count
<DIV>
<DIV class=h5><BR><BR>Hello, 
<DIV><BR></DIV>
<DIV>I have a .NET managed module handling calls transferred to it via dial plan.</DIV>
<DIV><BR></DIV>
<DIV>Now, I would like to maintain concurrent call count and decline the call if it has reached certain limit.</DIV>
<DIV><BR></DIV>
<DIV>What I do is, have a static variable to track this.</DIV>
<DIV><B>private static int mIntCurCalls = 0;</B></DIV>
<DIV><BR></DIV>
<DIV>Then, when Run() is executed, I&nbsp;<B>mIntCurCalls++</B>&nbsp;after answering the call.</DIV>
<DIV><BR></DIV>
<DIV>I perform check <B>if mIntCurCalls &gt; "max allowed calls"</B> then I play a message and hangup.</DIV>
<DIV><BR></DIV>
<DIV>I&nbsp;<B>mIntCurCalls--</B>&nbsp;this when call is hung up.</DIV>
<DIV><BR></DIV>
<DIV>Since last few days users have been complaining they get "busy" or "number not available" when dialing toll-free number.</DIV>
<DIV><BR></DIV>
<DIV>However, I don't see them getting the message that I have in the code.</DIV>
<DIV><BR></DIV>
<DIV>Is the method of keeping call count correct?</DIV>
<DIV><BR></DIV>
<DIV>Thanks.</DIV>
<DIV><BR></DIV></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></DIV><BR>_________________________________________________________________________<BR>Professional FreeSWITCH Consulting Services:<BR><A href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</A><BR><A href="http://www.freeswitchsolutions.com/">http://www.freeswitchsolutions.com</A><BR><BR>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<BR><A href="http://www.cudatel.com/">http://www.cudatel.com</A><BR><BR>Official FreeSWITCH Sites<BR><A href="http://www.freeswitch.org/">http://www.freeswitch.org</A><BR><A href="http://wiki.freeswitch.org/">http://wiki.freeswitch.org</A><BR><A href="http://www.cluecon.com/">http://www.cluecon.com</A><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">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</A><BR>UNSUBSCRIBE:<A href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</A><BR><A href="http://www.freeswitch.org/">http://www.freeswitch.org</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV></BLOCKQUOTE>
<STYLE>
</STYLE>

<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></body></html>