Symbian RThread 问题
我有这样的代码:
void MyAppAppUi::ConstructL()
{
_LIT(KString1, "asd");
TBuf<15> buf1(KString1);
TInt iStackSize = 32000;
RThread iThread;
TInt err = iThread.Create(
buf1,
func,
iStackSize,
NULL,
NULL
);
iThread.Resume();
}
TInt func(TAny *obj)
{
CAknInformationNote* note = new(ELeave)CAknInformationNote;
TBuf<32> msg;
msg.Format(_L(" rasdasd "));
note->ExecuteLD(msg);
}
在头文件中这样:
friend TInt func(TAny *obj);
问题是它没有进入函数: func
err 等于 KErrNone
I have this code:
void MyAppAppUi::ConstructL()
{
_LIT(KString1, "asd");
TBuf<15> buf1(KString1);
TInt iStackSize = 32000;
RThread iThread;
TInt err = iThread.Create(
buf1,
func,
iStackSize,
NULL,
NULL
);
iThread.Resume();
}
TInt func(TAny *obj)
{
CAknInformationNote* note = new(ELeave)CAknInformationNote;
TBuf<32> msg;
msg.Format(_L(" rasdasd "));
note->ExecuteLD(msg);
}
and in the header file this:
friend TInt func(TAny *obj);
The problem is that it doesn't enter in the function: func
err is equal to KErrNone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为该线程正在运行,但问题是您正在运行的线程失败了。
主要问题是您正在尝试在另一个线程中执行 UI 代码。这通常不起作用,在主线程上创建所有 UI 内容。所以你的代码无论如何都不会工作。
您还需要了解 Symbian 概念,例如资源管理(清理堆栈)和活动对象。
一般来说,当您启动 Symbian 线程时,您需要使用标准 Symbian 基础设施来设置该线程。您几乎总是需要在新线程上设置一个清理堆栈,并且您可能需要选择设置一个 ActiveScheduler(尽管在启动 ActiveScheduler 之前至少需要一个活动对象)。
请参阅此 Nokia RThread 示例,了解如何创建和管理线程。
稍微分解一下示例:
您需要清理堆栈基础结构:
如果您需要使用活动对象,您还需要设置 ActiveScheduler:
I think that the thread is running, but the problem is what you are running is failing.
The main problem is that you are trying to do UI code in another thread. This will generally not work, create all UI stuff on your main thread. So your code will never work anyway.
Also you need to learn about Symbian concepts like the there resource management (cleanup stack) and active objects.
Generally, when you start a Symbian thread you need to setup the thread with standard Symbian infrastructure. You almost always need to setup a cleanup stack on the new thread, and you may need to optionally setup a ActiveScheduler (altho you need at least one active object before you start the ActiveScheduler).
See this Nokia RThread example on how to create and manage a thread.
To break the example down a little:
You need the cleanup stack infrastructure:
If you need to use Active Objects you need to also setup the ActiveScheduler: