<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2160/1/7/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Tips+and+Tricks">Tips and Tricks</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~mnicholson">Matthew Nicholson</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2. Long Running Operations (Autoservcie) <br> <br>Before starting long running operations, an autoservice should be started using the {{autoservice_start()}} function. An autoservice will ensure that the user hears a continuous stream of audio while your lua code works in the background. This autoservice will automatically be stopped before executing applications and dialplan functions and will be restarted afterwards. The autoservice can be stopped using autoservice_stop() and the autoservice_status() function will return {{true}} if an autoservice is currently running. <br> <br>{code} <br>app.startmusiconhold() <br> <br>autoservice_start() <br>do_expensive_db_query() <br>autoservice_stop() <br> <br>app.stopmusiconhold() <br>{code} <br> <br>{note} <br>In Asterisk 1.10 an autoservice is automatically started for you by default. <br>{note} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        
<h2><a name="TipsandTricks-LongRunningOperations%28Autoservcie%29"></a>Long Running Operations (Autoservcie)</h2>

<p>Before starting long running operations, an autoservice should be started using the <tt>autoservice_start()</tt> function. An autoservice will ensure that the user hears a continuous stream of audio while your lua code works in the background. This autoservice will automatically be stopped before executing applications and dialplan functions and will be restarted afterwards. The autoservice can be stopped using autoservice_stop() and the autoservice_status() function will return <tt>true</tt> if an autoservice is currently running.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">app.startmusiconhold()

autoservice_start()
do_expensive_db_query()
autoservice_stop()

app.stopmusiconhold()</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>In Asterisk 1.10 an autoservice is automatically started for you by default.</td></tr></table></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://wiki.asterisk.org/wiki/display/AST/Tips+and+Tricks">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=16548028&revisedVersion=2&originalVersion=1">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/Tips+and+Tricks?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>