On my own created thread I'm doing this:
The loop works fine and the messages are handled in my MMsvSessionObserver::HandleSessionEventL implementation. iSchedulerWait is of type CActiveScheduleWait. This thread handles the message creation/modification in the scheduler's loop. iMsvSession is the active object, which handles the messages to my observer.
iScheduler = new (ELeave) CActiveScheduler();
iMsvSession = CMsvSession::OpenSyncL(*this);
iSchedulerWait.Start(); // starts the loop, don't finishes until AsyncStop AND any session event AFTER that
When I'm trying to stop this loop from the main thread by calling:
AsyncStop doesn't stop the loop, until any session event arrives.
User::WaitForRequest(iThreadStatus); // hangs until any session event
How to stop this thread correctly?
Maybe CMsvSession creates some nested scheduler loops?
If so, how to stop them?
I've tried calling iMsvSession->Cancel(), iMsvSession->RemoveObserver(*this) or delete iMsvSession before AsyncStop, all of them leave/panic.