开源项目async-threading能使as3支持多线程,google code地址:http://code.google.com/p/async-threading/
要在flex4 sdk环境下使用,要先修改一下源代码,打开com.symantec.premiumServices.asyncThreading.handlers.FPSObserverHandler
将import mx.core.Application; 修改为import spark.components.Application;
将private var _appRef:Application = Application.applicationas Application;修改为private var _appRef:Application = FlexGlobals.topLevelApplication as Application;
同时导入import mx.core.FlexGlobals;
这个api要求自定义的线程继承AbstractAsyncThread然后实现IAsyncThreadResponder接口,写一个测试用线程:
package thread
{
import com.symantec.premiumServices.asyncThreading.abstract.AbstractAsyncThread;
import com.symantec.premiumServices.asyncThreading.interfaces.IAsyncThreadResponder;
/**
* 自定义线程
*/
public class SelfDefinedThread extends AbstractAsyncThread implements IAsyncThreadResponder
{
private var f:Function;
public function SelfDefinedThread(f:Function)
{
super();
this.f = f;
}
public function execute():void
{
f.call();
}
}
}
这个api还是比较强大的,基本线程操作和通讯都能实现了,具体可以看附件内的源代码api。
这个线程的构造函数要传入一个方法,这个方法将在线程启动后调用。
测试代码:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="testThread()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import thread.SelfDefinedThread;
private function testThread():void{
//线程1
var thread1:SelfDefinedThread = new SelfDefinedThread(
function():void{
trace("线程1执行");
trace("开启线程2");
thread2.start();
});
//线程2
var thread2:SelfDefinedThread = new SelfDefinedThread(
function():void{
trace("线程2执行");
if(thread1.sleeping)
{
thread1.kill();
thread2.kill();
thread3.kill();
trace("线程1,2,3终止");
}else{
trace("开启一个线程3");
thread3.start();
}
});
//线程3
var thread3:SelfDefinedThread = new SelfDefinedThread(
function():void{
trace(thread3.id + "线程3执行");
if(!thread1.sleeping)
{
thread1.sleep();
trace("线程1休眠");
}
});
thread1.priority = thread1.RUN_LEVEL_HIGH;
thread2.priority = thread2.RUN_LEVEL_BELOW_NORMAL;
thread1.start();
}
]]>
</fx:Script>
<s:Label x="281" y="122" text="多线程测试"/>
</s:WindowedApplication>
用调试模式执行就能看到结果:
分享到:
相关推荐
NULL 博文链接:https://fzlihui.iteye.com/blog/953299
Microsoft.VisualStudio.Threading 分析仪: 产品特点 许多线程同步原语的异步版本 AsyncAutoResetEvent AsyncBarrier AsyncCountdownEvent AsyncManualResetEvent AsyncReaderWriterLock AsyncSemaphore ...
在python中启动和关闭线程: 首先导入threading import threading 然后定义一个方法 def serial_read(): … … ...def _async_raise(tid, exctype): """raises the exception, performs cleanu
AsyncAwaitBestPractices System.Threading.Tasks.Task扩展。 受( )的博客文章启发:。AsyncAwaitBestPractices 在NuGet上可用: : SafeFireAndForget 一种安全触发并忘记Task或ValueTask的扩展方法确保Task将重新...
Advanced - Multithreading - How-To Async Calls Advanced - Remoting - How-To TCP Remoting Advanced - Serialization - How-To Serializing Objects Advanced .NET Framework (GDI+) - Animation with GDI+ ...
一组扩展,用于优化/简化System.Threading.Channels的用法。 强调 读写 具有可选的并发级别。 读取通道中的所有条目。 将所有条目从源写入通道。 将所有条目管道传输(使用)到缓冲区(通道)。 .NET Standard ...
关于Python3中Asyncio库的详细介绍与示例: ...user developers and those for framework developers Understand Asyncio’s new async/await language syntax, including coroutines and task and future APIs
F#拥有自己的Async类型,并具有在Async和Task之间来回转换的功能,但这有点麻烦-尤其是因为Task现在在C#和VB.NET中具有语言级别的支持,所以事实上.NET上的异步标准。 此外,F#的Async行为与Task略有不同,如果...
from threading import Thread def async_call(fn): def wrapper(*args, **kwargs): Thread(target=fn, args=args, kwargs=kwargs).start() return wrapper test.py from time import sleep from async_call ...
穿线 线程是协作的,非抢占式多任务处理(软件线程)的实现。 也可以与任何第三方库结合使用以进行并行计算(用于协调和同步)。...import "dart:async" ; import "package:threading/threading.dart" ; Future main
import threading import time import inspect import ctypes def _async_raise(tid, exctype): """raises the exception, performs cleanup if needed""" tid = ctypes.c_long(tid) if not inspect.isclass...
EurekaLog 7.5 (18-August-2016) 1)..Important: Installation layout was changed. All packages now have version suffix (e.g. EurekaLogCore240.bpl). No files are copied to \bin folder of IDE....
异步日志 asynclog提供了python日志记录的异步方式。 将日志记录I / O(尤其是当我们要登录到网络端点时的网络I / O)留给提供的异步线程或异步任务。 要求 Python 3.5+ ... 'async_handler' : { 'level
PEP 492 - Coroutines with async and await syntax PEP 465 - A dedicated infix operator for matrix multiplication PEP 448 - Additional Unpacking Generalizations PEP 461 - percent formatting support ...
using System.Threading.Tasks;using TmxMapperPCL;....private async Task<StorageFile> GetStorageFile() { StorageFolder installedLocation = Windows.ApplicationModel.Package.Current....
产品特点几乎不改变使用量,或将几乎所有模块卸载到Worker中支持任意的类,对象和函数( await new Foo() ) 与async / await完美搭配内置代码拆分:工人被延迟加载安装npm install -D comlink-loader用法comlink-...
将任何方法转换为其异步实现AsyncConverter可以: 用通用或非通用Task或Task替换返回类型将覆盖方法的层次结构从重命名为<MethodName> Async 将System.Threading.Tasks添加到usings声明分析方法主体,并将每个同步...
threading tips(31KB)<END><br>44,direct_sql_with_odbc.zip Classes for direct SQL calls with ODBC(4KB)<END><br>45,generic_recordset.zip The Generic Recordset(2KB)<END><br>46,generaltabledef.zip...
在 C# 中,使用 System.Threading 命名空间来创建和管理多线程。 1.线程池 (Thread Pool): 线程池是用于执行异步任务的托管线程集合。当你想执行许多类似的异步任务时,使用线程池可以有效地管理资源。 2.创建新线程...
将微型的专用RPC实现捆绑到您的应用中如果导出的模块方法已经异步,则签名不变支持同步和异步工作程序功能与async / await完美搭配压缩后的ES3仅800字节安装npm install --save workerize用法传递函数或包含代码的...