Results 1 to 2 of 2

Thread: Cannot stop running task when call Ext.TaskManager.stop() method!

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default Cannot stop running task when call Ext.TaskManager.stop() method!

    I set up a message box to display current time. The timer interval set as 1000, and there are 2 buttons to start and stop the 'timer'. When click on the 'stop' button it calls the Ext.TaskManager.stop method and update the text in the message box to 'paused'. However, when clicked the 'stop' button and the text changed to 'Paused' for just second, it changed back to display current time again. When i tried use Ext.TaskManager.stopAll(); instead of Ext.TaskManager.stop(task), it works! Why? My code as below:
    Code:
    <script type="text/javascript">
    
    
        Ext.onReady (function(){
            
            var config={
    
    
                    msg:'Display Time',
                    modal:true,
                    buttons:Ext.Msg.OKCANCEL,
                    fn:displayTime
                }
                
                Ext.MessageBox.msgButtons[0].setText('Start');
                Ext.MessageBox.msgButtons[3].setText('Stop');    
                
                Ext.MessageBox.show(config);
            
                function displayTime(id){
                    
                    if(id=='ok'){
                        
                        var task = {
                            run:function(){Ext.MessageBox.updateText ('????:' + Ext.util.Format.date(new Date(), 'Y-m-d g:1:s A'));},        
                            interval:1000                            
                            }
                        
                        Ext.TaskManager.start(task);
                    }
                    
                    else {
    
    
                        Ext.MessageBox.updateText('Paused!');
                        Ext.TaskManager.stop(task);
                    }    
            };
            
            });
    
    
    </script>

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,409
    Answers
    716
    Vote Rating
    504
      0  

    Default

    Please see the following changes:

    Code:
    var config = {
    
    
        msg: 'Display Time',
        modal: true,
        buttons: Ext.Msg.OKCANCEL,
        fn: displayTime
    }
    
    Ext.MessageBox.msgButtons[0].setText('Start');
    Ext.MessageBox.msgButtons[3].setText('Stop');
    
    Ext.MessageBox.show(config);
    
    function start_task() {
       Ext.MessageBox.updateText('????:' + Ext.util.Format.date(new Date(), 'Y-m-d g:1:s A')); 
    }
    
    var task = { // moved outside function so it was not called over and over
        run: start_task,
        scope: this,
        interval: 1000
    }
    
    function displayTime(id) {
       
        if (id == 'ok') {
           // task was here ... was not always defined due to if statement; was also recalled each time
           Ext.TaskManager.start(task);
        } else {
            Ext.MessageBox.updateText('Paused!');
            Ext.TaskManager.stop(task);
        }
    };
    Regards,
    Scott.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •