Using CActiveSchedulerWait
来源:互联网 发布:我国大数据研究方向 编辑:程序博客网 时间:2024/05/15 16:44
From Forum Nokia Wiki
Knowledge Base Home
ID CS000982 Creation date May 28, 2008
Platform S60 3rd Edition, MR Tested on devices Nokia N95
Category Symbian C++ Subcategory Code Examples
Keywords (APIs, classes, methods, functions): CActiveSchedulerWait, CActiveScheduler, RThread
Overview
CActiveSchedulerWait controls a single scheduling loop in the current global CActiveScheduler active scheduler. CActiveSchedulerWait provides better control of nested wait loops in the active scheduler.
Note that a CActiveSchedulerWait object can be used as a data member inside other CBase-derived classes.
See also the code example about threads CS000867 - RThread.
Source: creating and starting CActiveSchedulerWait
Execute RThread:
TInt CSomeThread::ExecuteThread(TAny *aPtr)
{
// Create cleanupstack
CTrapCleanup* cleanupStack = CTrapCleanup::New();
// Create active sheduler and start thread
TRAPD( error, CThreadAOEngine::CreateActiveSchedulerL( sharedMediator ) )
delete cleanupStack;
return 0;
}
Start the active scheduler and the asynchronous operation:
void CSomeThread::CreateActiveSchedulerL()
{
// 1. Create a new active scheduler.
CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
CleanupStack::PushL(activeScheduler);
// 2. Use the static function Install to install the previously created scheduler.
CActiveScheduler::Install(activeScheduler);
// 3. Created a nested loop inside CActiveScheduler.
CActiveSchedulerWait* wait = new (ELeave) CActiveSchedulerWait;
CleanupStack::PushL(wait);
// 4. Create a class that must be handled asynchronously.
CSomeAsyncClassTimer* timer = CSomeAsyncClassTimer::NewL(wait);
CleanupStack::PushL(timer);
// 5. Add an active object in CActiveScheduler.
CActiveScheduler::Add(timer);
// 6. Active scheduler must have one outstanding request before it can
// be started.
timer->StartL();
// 7. Start the nested scheduler loop.
wait->Start();
// 8. The process continues here after calling CActiveSchedulerWait::AsyncStop()
// that is called in CSomeAsyncClassTimer::StopWaitLoop()
// Remove and delete the scheduler and the rest.
CleanupStack::PopAndDestroy(3);
}
Source: stopping CActiveSchedulerWait
void CSomeAsyncClassTimer::StartL()
{
// TODO: An asynchronous operation starts in
// this CActive object
}
void CSomeAsyncClassTimer::RunL()
{
// Asynchronous operation stops
// We desided to stop our own CActiveSchedulerWait
StopWaitLoop();
// NOTE: This does not stop the global CActiveScheduler but it continues
// running.
}
void CSomeAsyncClassTimer::StopWaitLoop()
{
Cancel();
// Stops our own nested scheduler loop
iActiveSchedulerWait->AsyncStop();
}
Postconditions
CActiveSchedulerWait, a nested wait loop, has been created in global CActiveScheduler. CActiveSchedulerWait stopped after running the asynchronoys operation. CActiveSchedulerWait does not stop the global CActiveScheduler but it continues running.
- Using CActiveSchedulerWait
- 利用CActiveSchedulerWait 将异步操作转换为同步
- 利用CActiveSchedulerWait 将异步操作转换为同步
- 利用CActiveSchedulerWait 将异步操作转换为同步
- using()
- using
- using
- using
- Using
- using
- using
- using namespace&using
- Using log4net
- Using log4net
- Using Cursor
- Using Timer
- Using Opera...
- using声明
- dbms_random.value 随机数问题 & 用DBMS_RANDOM生成文本和日期值
- 吓我一跳,原来如此
- Hibernate缓存的使用
- [wxPython]python3 中文邮件
- MFC 窗口静态切分
- Using CActiveSchedulerWait
- 如何在asp.net中实现返回上一页的功能
- modem的at指令集大全
- ArcGIS 9.3 破解后 ArcGlobe、ArcScene不能用(Generating ArcID Module)的解决办法
- 开始学习
- [经验总结]近期JavaScript编程总结
- Vxworks编译中出现bootInit.o Error 0x1 解决方法
- datalist控件ItemCommand与DataList1_ItemDataBound编程实例,使用示例数据库
- 关注内心