Here is a more detailed code-snippet (not a 1to1 copy, but you should get the idea what I am trying to do). The real code I am using compiles and starts (so any syntax errors in here means I typed the code incorrectly into this post, not that the real code has a syntax error..). The GUI works etc.
What I am trying to do is basically find out, what programming approcahes I can use on symbian. I just want to find out what works and what should work but dosen't..
I have a GUI application (AppUi being one class of it) with a menu where I can select SomeCommand. I handle this message in AppUi HandleCommand(). There I start myThread, pass the ThreadId of the GUI thread and AppUi::iStatus (AppUi inherits from CActive). Then I do some work in the myThread and want to notify AppUi that the work is finished. But I never get AppUi::RunL() to execute. AppUi is working fine otherwise, as well as MyThread (the thread runs).
Code:
class AppUi;
class MyThread;
// AppUi my derivation of the standard framework UI class.
class AppUi : public CAknAppUi, public CActive {
// ..standard AppUi class stuff..
// ..omitting all the uninteresting details,
// the gui is up & running (menu works etc.)
AppUi() : CActive(EPriorityStandard) {
CActiveScheduler::Add( this );
}
MyThread* myThread;
void RunL() {
// do something
}
void DoCancel() {}
// here is a snippet from the correctly running HandleCommandL
void HandleCommandL(TInt aCommand)
{
switch (aCommand)
// ..
{
// getting this command works correctly..
case ESomeCommand:
{
// Create myThread and pass this (UI) thread's Id.
myThread = new MyThread();
myThread->rqStatus = &iStatus;
myThread->rqThreadId = RThread().Id();
myThread.thr.Resume();
// let's say this thread has debugIdUi = 449
TUint64 debugIdUi = RThread().Id().Id();
// Since I want myThread to provide an active object service,
// I call SetActive() for AppUi
SetActive();
}
break;
}
//..
//..
}
};
class MyThread {
// ..omitting constructor which creates the thread correctly
RThread thr;
TRequestStatus* rqStatus=NULL;
TThreadId rqThreadId;
// this is the run-function that runs in thr.
virtual void threadRunFunction() {
bool shouldRun = true;
// let's say this thread has debugIdMyThread = 450
TUint64 debugIdMyThread = RThread().Id().Id();
while (shouldRun) {
// do some task ..
// Notify about some task completed
if (rqStatus) {
RThread extThr;
int err = extThr.Open( rqThreadId );
// err == 0 (NO ERROR)
*rqStatus = KRequestPending;
// Contrary to what I would expect, debugExternalIdUi==2151349783 (or some other "random" value)
// but it is definetily not debugIdUi==449.
// I am not sure if opening a handle to a thread automatically assigns the same ThreadId to the handle.
TUint64 debugExternalIdUi = extThr.Id().Id();
extThr.RequestComplete( rqStatus, 1234 );
extThr.Close();
}
// this thread still runs after issuing RequestComplete, it should handle other tasks..
}
}
}