Asynchronous DirectMethod

Page 3 of 3 FirstFirst 123
  1. #21
    Hi,

    Here is the sample
    <%@ Page Language="C#" Async="true" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
          public delegate string AsyncMethodCaller();
    
          [DirectMethod(ShowMask=true)]
          public void LongTask()
          {
              this.AddOnPreRenderCompleteAsync(delegate(object sender, EventArgs e, AsyncCallback cb, object state)
              {
                  AsyncMethodCaller caller = new AsyncMethodCaller(GenerateData);
                  return caller.BeginInvoke(cb, caller);
              }, 
              delegate(IAsyncResult ar)
              {
                  AsyncMethodCaller caller = (AsyncMethodCaller)ar.AsyncState;
    
                  string data = caller.EndInvoke(ar);
                  this.Context.Items["ExtNetParam_DirectMethodResult"] = data;
              });
          }      
    
          protected string GenerateData()
          {
              //method that generates some data
              System.Threading.Thread.Sleep(5000);
              return "test data";
          }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:Button runat="server" Text="Call long task">
                <Listeners>
                    <Click Handler="#{DirectMethods}.LongTask({success : function(result){Ext.Msg.alert('Data', result);}});" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
  2. #22
    Hi Vlad,
    I checked ur code... and there is a slight problem.
    When I debug, and watch the Threads in use, it still uses Worker Thread. Also where I check System.Threading.Thread.CurrentThread.isThreadPool Thread it returns true.

    In Rahul's solution, its false which certainly means the worker thread pool is free to use and not occupied.
Page 3 of 3 FirstFirst 123

Similar Threads

  1. AjaxMethod - is it Asynchronous
    By glenh in forum 1.x Help
    Replies: 2
    Last Post: Jul 12, 2012, 9:34 PM
  2. DirectMethod NullReferenceException
    By bayoglu in forum 1.x Help
    Replies: 2
    Last Post: Apr 04, 2012, 4:26 PM
  3. Replies: 2
    Last Post: Feb 02, 2012, 5:30 AM
  4. [CLOSED] Difference between DirectMethod , DirectEvent, Static DirectMethod
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 11:37 AM
  5. Synchronous DirectMethod?
    By glenh in forum 1.x Help
    Replies: 1
    Last Post: Sep 14, 2010, 5:11 AM

Posting Permissions