×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    fail to open contacts when use thread to visit contacts

    i create a new thread in my program based on S60.i debug my program by using VC IDE on S60 emulator. when the thread tried to open contact database,the thread was closed after failing to open contact database. i have used many ways to find the reason, i failed.who can tell me the reason?

    my code in the follow:
    void XXXXXXXX::CreateThread()
    {
    TInt error = iThreadHandlePackage.Create(_L( "HandlePackageByThread") ,
    HandlePackageByThread,
    1024*10, //stack size
    1024*10, //min heap size
    1024*60, //max heap size
    iSyncInfo,
    EOwnerThread);
    if(error != KErrNone)
    return;
    iThreadHandlePackage.Resume();

    iThreadCreated = ETrue;
    iThreadRunning = ETrue;
    }
    TInt XXXXXXX::HandlePackageByThread(TAny *aPtr)
    {
    CContactDatabase* contactsDb;
    TRAPD(error,contactsDb = CContactDatabase::OpenL();
    if(error != KErrNone)
    return FAIL_OPEN_DATABASE;
    delete contactsDb;
    }

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    8

    Re: fail to open contacts when use thread to visit contacts

    Hi, i got the similar problem with anotha function FindWildByDir.
    Actually, I had 3 issues:
    - Define a cleanupstack
    - TRAPD(myFunc)
    - use & install an Activesheduler

    I'm still having the problem, check "RThread FindWildByDir", I may get some cool answers
    Mike

  3. #3
    Regular Contributor
    Join Date
    May 2004
    Location
    Melbourne, Australia
    Posts
    75

    Re: fail to open contacts when use thread to visit contacts

    hello,
    Try initialising the CContactDatabase pointer, ie
    CContactDatabase* contactsDb = 0;

    Hope that helps,
    Aymen

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Re: fail to open contacts when use thread to visit contacts

    hi,aymenn, thanks for your advise.
    i tried by your method again.but it is not useful to resolve the program.

  5. #5
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: fail to open contacts when use thread to visit contacts

    Try installing an active scheduler if you can't open the contacts database.
    Last edited by hotcheese; 2006-02-28 at 23:47.

  6. #6
    Regular Contributor
    Join Date
    May 2004
    Location
    Melbourne, Australia
    Posts
    75

    Re: fail to open contacts when use thread to visit contacts

    In hindsight, I can see that if OpenL fails, the delete is never reached...

    Still a good habit to get into i would say.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Re: fail to open contacts when use thread to visit contacts

    i think it is symbian OS limitation. multi-threaded programs are uncommon in Symbian OS,some resources can only be used from the main thread.

  8. #8
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: fail to open contacts when use thread to visit contacts

    As Hotcheese said, you need to have an active scheduler to use the contacts database.

    More importantly you need to create a cleanup stack before you can use trap.

    Look in the sample code or download the example for forum nokia for examples on using a thread and active objects

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Re: fail to open contacts when use thread to visit contacts

    thank for Paul's reply.i downloaded thread example project and add my code into thread function:
    TInt CThreadEngine::ExecuteThreadTwo(TAny *aPtr)
    {
    // Convert pointer
    CContactDatabase* contactsDb = NULL;


    TRAPD(error,CleanupStack::PushL(contactsDb = CContactDatabase::OpenL(CContactDatabase::EMultiThread)));

    if(error != KErrNone)
    return error;
    contactsDb->CloseTables();
    CleanupStack::PopAndDestroy();

    return KErrNone;


    }

    void CThreadEngine::ConstructL(CThreadAppView* aView)
    {
    CTimer::ConstructL();

    iView = aView;
    CActiveScheduler::Add( this );
    }

    i got the same result:fail to open contactdatabase!!!

  10. #10
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: fail to open contacts when use thread to visit contacts

    Are you sure you you read the document?


    You actually missed the most important point of my response which is that you need to create a cleanup stack before creating your active scheduler.

    The following are missing:
    Create a cleanup stack using a CTrapCleanup.
    Create an active scheduler object for the thread.
    Install an active scheduler on the thread for the thread.

    Also I hope CThreadAppView is not derived from CView, you cannot use views across threads.

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Re: fail to open contacts when use thread to visit contacts

    Thank you,Paul. can you tell me how to Create an active scheduler object for the thread and Install an active scheduler on the thread for the thread?

  12. #12
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: fail to open contacts when use thread to visit contacts

    I don't normally do peoples homework assignments for them but here is a simple example

    TInt XXXXXXX::HandlePackageByThread(TAny *aPtr)
    {
    CTrapCleanup* cleanupStack = CTrapCleanup::New();
    CActiveScheduler* activeScheduler = new CActiveScheduler;
    CActiveScheduler::Install(activeScheduler);

    // add your code here

    // add some cleanup code do destroy the scheduler and cleanup objects
    }

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Re: fail to open contacts when use thread to visit contacts

    I resolved my problem eventually by Paul's methods. Thank Paul very much.

  14. #14
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    182

    fail to open contacts when use thread to visit contacts

    I am also implementing the thread for contacts,same problem i am getting, i am not able to open contact data base.if any one know reply me, i am using the 3rd edition.


    TInt xxxxxxxxx::GetContactListL(RContactDetailsArray** aContactNamesDPtr)
    {

    TInt lResult = KErrNone;
    lResult = iContactsThread.Create( KContactThread,
    xxxxx::GetContactsThreadFunction,
    KDefaultStackSize,
    KMinHeapSize,
    KMinHeapSize+1000000,
    this);
    iContactsThread.SetPriority( EPriorityRealTime );
    iContactsThread.Resume();

    *aContactNamesDPtr = iContactDetailsArray;

    return lResult;


    }

    TInt xxxxxxxxx::GetContactsThreadFunction(TAny *aData)
    {
    TInt lResult = KErrNone;
    xxxr* lxx = static_cast<xxxxxxx*> (aData);

    CTrapCleanup* lCleanupStack = CTrapCleanup::New();
    TRAPD(lTrapErr,lContactDBManager->GetContactList());
    if(lTrapErr != KErrNone)
    {
    lResult = lTrapErr;

    }
    delete lCleanupStack;

    return lResult;
    }


    void xxxx::GetContactList()
    {
    TInt lResult = KErrNone;

    if (NULL != iContactDbPtr)
    {
    delete iContactDbPtr;
    iContactDbPtr = NULL;
    }
    CActiveScheduler* lActiveScheduler;
    lActiveScheduler = new( ELeave )CActiveScheduler;
    CActiveScheduler::Install( lActiveScheduler );
    TRAP(lResult, iContactDbPtr = CContactDatabase::OpenL(CContactDatabase::EMultiThread));//here it's not opening

    .........................
    ...................
    }

  15. #15
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: fail to open contacts when use thread to visit contacts

    You don't start the active scheduler

Page 1 of 2 12 LastLast

Similar Threads

  1. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46
  2. Open File in other thread
    By TrungThanhMtad in forum Symbian C++
    Replies: 1
    Last Post: 2005-10-13, 03:14
  3. Replies: 1
    Last Post: 2003-08-21, 03:59
  4. visit wap site via active server fail n8310
    By jingshengshi in forum WAP Servers
    Replies: 1
    Last Post: 2003-05-26, 08:58
  5. Open the contacts database fail......
    By tntfighter-2002 in forum Symbian C++
    Replies: 1
    Last Post: 2002-09-23, 11:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •