Symbian 创建线程

声明
RThread  iThread;
TBool StartThread(void); 
static TInt  ThreadRun(TAny *aPtr);
实现
StartThread(void)
{
    TInt re = EFalse;
     iThread.Close();       
     _LIT(ThreadName, "Thread");  
    TInt err = iThread.Create(ThreadName , ThreadRun, 10240, KMinHeapSize, 4096*KMinHeapSize, this , EOwnerProcess );   
    if(err == KErrNone)
    {
        iThread.Resume();       
        re = ETrue;
    }
    return re;
}

ThreadRun(TAny *aPtr)
{
    CParenApp*  myparent = static_cast<CParenApp*>(aPtr);
    CTrapCleanup* cleanup = CTrapCleanup::New();   
    TRAPD(err,myparent->DoSomething());
    if(err != KErrNone)
   {
   }
    delete cleanup;
    return KErrNone;
}
释放
//iThread.Kill(KErrNone); 
iThread.Close();
1、线程中如果不使用清理栈可以不创建。
2、如果线程不是无限久,可以在最后加一个循环,这样可以调用iThread.Kill(KErrNone)结束。
3、线程当中能使用静态变量与法,其他可以通过传入指针间接使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值