CMyActiveObject* activeObj = CMyActiveObject::NewLC(); TRequestStatus status; activeObj->DoSomething(status); User::WaitForRequest(status); if (status.Int() == KErrNone) { // Operation completed successfully } else { // Operation failed with error code 'status.Int()' } CleanupStack::PopAndDestroy(activeObj);
CMyActiveObject* activeObj = CMyActiveObject::NewLC(); TRequestStatus status; // Start asynchronous operation activeObj->DoSomething(status); // Cancel operation after 5 seconds User::After(5000000); // 5 seconds activeObj->Cancel(); // Wait for completion User::WaitForRequest(status); if (status.Int() == KErrCancel) { // Operation was canceled } else if (status.Int() == KErrNone) { // Operation completed successfully } else { // Operation failed with error code 'status.Int()' } CleanupStack::PopAndDestroy(activeObj);In this example, the asynchronous operation is started with DoSomething() method. After 5 seconds, the Cancel() method is called on the active object to cancel the operation. The WaitForRequest() method is called to wait for the operation to complete. When the operation completes, the result is checked. If the operation was canceled, then the Int() method of the TRequestStatus object will return KErrCancel. If the operation completed successfully, the Int() method of the TRequestStatus object will return KErrNone. Otherwise, an error occured and the error code will be returned. Package library: TRequestStatus is part of the Symbian OS C++ API. Specifically, it is located in the e32base.h header file which belongs to the EPOC32.STATIC.LIB library.