timing issue with BlockUI?

timing issue with BlockUI?

I used the following code to register block and unblock. The code is innocent enough. However I found that it does not work with quick ajax calls. I suspect that, if the ajax call is quick, it hits some timing issue in BlockUI, and cause the unblock somehow happens before block (?) - as a result, the dialog never goes away.

(It does work for most of my pages and ajax calls, but not one that makes a quicker ajax call.)
  1. <cc1:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" SupportsPartialRendering="true"></cc1:ToolkitScriptManager>
    <script type="text/javascript">
             Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(bar);
             Sys.WebForms.PageRequestManager.getInstance().add_endRequest(foo);
             function foo(sender, args) {
                     $.unblockUI;
             }
             function bar(sender, args) {
                     $.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });
             }
    </script>