ExtJs 진행률 표시줄(폴링)

6314 단어 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     }

좋은 웹페이지 즐겨찾기