[CLOSED] How to handle a callback using background threads?

  1. #1

    [CLOSED] How to handle a callback using background threads?

    Hi everyone!

    I would like to know how can I create new a thread to execute slow tasks and handle a callback.
    In the example below I have 3 buttons, the first do a slow task in the main thread, while the third do the same task but with a new thread. Notice that the second button waits the slow one to execute a fast job, an this is what I want to avoid with a new thread. I understand why this behaviour happens, I Just want a suggestion how can I easily parallelize server jobs without stuck the client.

    Thanks.

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Threading" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
      public void slowTask()
      {
        Thread.Sleep(5000);
        btnSlowTask.Enable();
        btnSlowTask.Icon = Icon.ControlPlay;
        btnSlowTask.Text = "Start Slow Task";    
      }
      public void fastTask()
      {
        System.Threading.Thread.Sleep(1000);
        btnFastTask.Enable();
        btnFastTask.Icon = Icon.ControlFastforward;
        btnFastTask.Text = "Start Fast Task";
      }
    
      [DirectMethod]
      public void startSlowTask()
      {
        slowTask();
      }
      [DirectMethod]
      public void startFastTask()
      {
        fastTask();
      }
    
      [DirectMethod]
      public void startSlowTaskWithThread()
      {    
        Thread slowTaskThread = new Thread(new ThreadStart(slowTask));
        slowTaskThread.Name = "ThreadFuncSlowTask";
        slowTaskThread.Start();
      }
      
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title>Question</title>
    </head>
    <body>
      <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Button ID="btnSlowTask" runat="server" Text="Start Slow Task" Icon="ControlPlay">
          <Listeners>
            <Click Handler="this.disable();this.setIconCls('#ControlStop');this.setText('Running...');App.direct.startSlowTask();" />
          </Listeners>
        </ext:Button>
        <ext:Button ID="btnFastTask" runat="server" Text="Start Fast Task" Icon="ControlFastforward">
          <Listeners>
            <Click Handler="this.disable();this.setIconCls('#ControlStop');this.setText('Running...');App.direct.startFastTask();" />
          </Listeners>
        </ext:Button>
        <ext:Button ID="btnSlowTaskWithNewThread" runat="server" Text="Start Slow Task With New Thread" Icon="ControlPlay">
          <Listeners>
            <Click Handler="this.disable();this.setIconCls('#ControlStop');this.setText('Running...');App.direct.startSlowTaskWithThread();" />
          </Listeners>
        </ext:Button>
      </form>
    </body>
    </html>
    Last edited by Daniil; Sep 06, 2014 at 8:26 AM. Reason: [CLOSED]
  2. #2
    Hi

    May be that example can help you
    https://examples2.ext.net/#/Miscella...r_Side_Update/
  3. #3
    I think the following thread is also going to be very helpful:

    http://forums.ext.net/showthread.php...ll=1#post72625
    Last edited by geoffrey.mcgill; Sep 05, 2014 at 8:04 PM.
    Geoffrey McGill
    Founder
  4. #4
    Thank you guys!

Similar Threads

  1. [CLOSED] How to cross link threads?
    By jwf in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 15, 2012, 10:38 PM
  2. No Email Notification for subscribed threads
    By dotnet in forum Open Discussions
    Replies: 5
    Last Post: Nov 08, 2012, 6:50 PM
  3. Callback
    By hbbazan in forum 1.x Help
    Replies: 0
    Last Post: Jul 28, 2009, 3:52 PM
  4. ASP.NET AJAX CallBack
    By tonymayoral in forum 1.x Help
    Replies: 2
    Last Post: Feb 07, 2009, 11:37 PM
  5. Change Tab background color or background image
    By georgelanes in forum 1.x Help
    Replies: 0
    Last Post: Nov 06, 2008, 3:55 PM

Posting Permissions