ExtJs 进度条(轮询)

  客户端代码:

      Ext.onReady(function () {
            Ext.get('mb').on('click', function () {
                Ext.Ajax.request({
                    url: root + "/Test/GetCount",
                    success: function (response) {
                        var sum = response.responseText;
                        Ext.MessageBox.show({
                            title: '删除',
                            msg: '正在删除...',
                            progressText: '',
                            width: 300,
                            progress: true,
                            closable: false,
                            animateTarget: 'mb'
                        });
                        f(sum);
                    },
                    failure: function () {
                    }
                });
            });
        });
        function f(v) {
            Ext.Ajax.request({
                url: root + "/Test/GetCurrentCount",
                success: function (response) {
                    var curnum = response.responseText;
                    if (curnum == 0) {
                        Ext.MessageBox.hide();
                    }
                    else {
                        var i = (v - curnum) / v;
                        Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed');
                        setTimeout(f(v), 1000);
                    }
                }
            });
        }

服务端耗时任务:

 1 public class TestController : Controller
 2     {
 3         private static int _count = 0;
 4         public int GetCount()
 5         {
 6             _count = 10;
 7             ThreadStart ts = new ThreadStart(RunBackThread);
 8             Thread td = new Thread(ts);
 9             td.Start();
10             return _count;
11         }
12         public int GetCurrentCount()
13         {
14             return _count;
15         }
16         public void RunBackThread()
17         {
18             while (_count > 0)
19             {
20                 Thread.Sleep(1000);
21                 _count--;
22             }
23         }
24     }

 

你可能感兴趣的:(ExtJs)