简体   繁体   English

Flex Web应用程序中的多线程

[英]Multithreading in flex web application

I am working on web application. 我正在开发Web应用程序。 In which i am stuck with some issue. 在其中我遇到了一些问题。

When i call some server function it will take time to get response. 当我调用某些服务器功能时,将需要一些时间来获得响应。 When response have high number of data. 当响应具有大量数据时。 It will get data, process on that data and update GUI in background. 它将获取数据,对该数据进行处理并在后台更新GUI。

Upto that my application GUI freeze. 直到我的应用程序GUI冻结。 I can not click on any part. 我无法单击任何部分。 I see some where that ActionScript support multithreading. 我看到一些ActionScript支持多线程的地方。 I found some tutorial for that which is here . 我在这里找到了一些教程。 But, it is for desktop application only. 但是,它仅适用于桌面应用程序。

Is there any way i can handle this freezing of application/GUI in web application. 有什么方法可以处理Web应用程序中的应用程序/ GUI冻结。 It will decrease my application performance and looks very bad. 它将降低我的应用程序性能,并且看起来非常糟糕。

Example: 例:

If i have list of data with checkbox and on checkbox click there is some process. 如果我有带有复选框的数据列表,并在复选框上单击,则有一些过程。 Now, there is one button called "Select All". 现在,有一个名为“全选”的按钮。 Now, if i click on "select all" then all check box selected and process on check selection is going and freeze the application upto process done. 现在,如果我单击“全选”,则所有复选框均已选中,选中检查的过程正在进行中,并冻结应用程序直至完成过程。

like: I have following list 喜欢:我有以下列表

<s:List id="tempList" itemRenderer="CustomItemRenderer" 
                    dataProvider="{someList}" useVirtualLayout="false"/>

ItemRenderer have label and checkbox as following. ItemRenderer具有标签和复选框,如下所示。

<s:CheckBox id="cCheckId" selected="{data.selected}" 
                change="onChangeHandler(event)" />
<s:Label id="lblTest"  />

protected function onChangeHandler(event:Event):void
{
    data.selected = !data.selected;
}

Now, on button Select all will select all check box. 现在,在全选按钮上将选中所有复选框。

<s:Button id="btnSelectAll" label="Select All" click="selectAllHandler(event)" />

protected function selectAllHandler(event:MouseEvent):void
{
  for(var i:int = 0;i<someList.length;i++)
  {
    someList[i].selected = true;
  }
}

Now, if someList have lots of data then it will freeze the screen. 现在,如果someList包含大量数据,那么它将冻结屏幕。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

The main idea behind the list and itemrenderers that you have a list (or datagrid) that displays like 30 items and then you can scroll to see the rest. 列表和itemrenderer背后的主要思想是,您有一个列表(或数据网格),该列表显示30个项目,然后您可以滚动查看其余的项目。 Then you will only have 30 Itemrenderers that would be updated at once. 这样一来,您将只有30个同时可更新的Itemrenderer。

If you don't want to scroll you will need to distribute your item selection over several frames, something like that (untested, but you get the idea) 如果您不想滚动,则需要将项目选择分布在几个框架上,类似的东西(未经测试,但您知道了)

private static const ITEMS_AT_ONCE:int = 5000;
private var _currentIndex:int;

protected function selectAllHandler(event:MouseEvent):void
{
    _currentIndex = 0;
    addEventListener(Event.ENTER_FRAME, onEnterFrame); // this will call the onEnterFrame method on each frame rendered
}

private function onEnterFrame(e:Event):void
{
    // make sure we don't run out of bounds of the dataprovider's length
    var maxIndex:int = Math.min(_currentIndex + ITEMS_AT_ONCE, someList.length);

    // set selection for the current bunch
    for (var i:int = _currentIndex; i < maxIndex; i++)
    {
        someList[i].selected = true;
    }

    if (maxIndex == someList.length)
    {
        // We are done, remove enterframe listener
        removeEventListener(Event.ENTER_FRAME, onEnterFrame);

        // I'm not sure but don't you need to refresh the dataprovider to reflect the changes in the ItemRenderers ?
        // (someList.dataProvider as ArrayCollection).refresh();
    }
    else
    {
        // update the _currentindex so we continue after this item on the next frame
        _currentIndex = maxIndex;
    }

Another possible solution - if you display all of them anyways - you might try to switch to a VGroup that will hold custom UIComponents (without MXML) for the items - this should speed up the rendering. 另一个可能的解决方案-如果仍然显示所有它们,则可以尝试切换到将容纳这些项目的自定义UIComponent(不包含MXML)的VGroup-这样可以加快渲染速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM