×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    15

    Question Simple Timer implementation Problem

    I have the following problem:
    I read the Article from your wiki about Simple Timer implementation.I did everything in my own project as you describe in the article with no eroors.What I want to do in my progrmam is the following (I describe a general schema:

    Code:
    void F1
    {
    
    DoStuff1();       // Part 1 of code in F1
    
    F2();            // ---->I want to make F2() to run every 10 seconds after the first time will be called
    
    DoStuff2();     // Part 2 of code in F1
    
    }
    How will I do that? Could you please send me a part of code of the ConstructL() function and/or of the TimerExpired that should be added??
    How can I tell the machine to do it every 10 seconds after the first time the F2() will be called?? Also a last question: The F2() call should be inside the F1() or inside of the TimerExpired Function as you describe in the article or anywhere else such as the After Function??


    IN YOUR WIKI YOU DECRIBE ONLY ABOUT AT,AFTER,INACTIVITY FUNCTIONS AND I CANT BE HELPED TO DO THE ABOVE I DESCRIBE.PLEASE ANYONE OF YOU DEAR NOKIA CHAMPIONS IF YOU KNOW ABOUT THAT SEND ME A PART OF CODE TO DO THAT.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Simple Timer implementation Problem

    You were already pointed to the Fibonacci examples a long time ago.
    If you choose the active-object-only approach (Fibonacci3 shows it), you have to decompose DoStuff1-2-...-n into small steps, as Fibonacci3 does. This approach works well with one or a few (would be) long running for loops. In this case your timer is a completely independent active object or CPeriodic (which is internally an active object).
    If you choose the threading approach (Fibonacci2 shows it), your DoStuff1-2-...-n could run in a separate thread, and your timer would still be an active object in your primary thread (I assume that you want to notify the user about progress, or something).

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

    Re: Simple Timer implementation Problem

    You think that one single wiki entry is the entire sum of documented information about active objects in the entire world?

    After I told you to read all you could about active objects and the active scheduler and to understand them what did you do exactly? Read that single page wiki entry again?

    You think you can simply be spoon fed a solution and it will be guaranteed to work with your entire program? What did I tell you about elephants.

    Let me let you into a secret, just because somebody posts a "solution" on here or is a forum nokia champion doesn't necessarily mean they know what they are talking about or are actually any good at proposing solutions. I wasn't asking you questions about the exact behaviour of your program and questions such as if your program is GUI based or console based for fun, its vital vital information as to what your solution will look like. If somebody gives you a bullshit solution are you going to be happy if you waste a few more days finding out it was bullshit.



    Ok assuming its GUI based and thus there is an active scheduler already installed,

    void F1
    {

    DoStuff1(); // Part 1 of code in F1

    iActive->After(10 seconds);

    DoStuff2(); // Part 2 of code in F1

    }

    The middle line will call CExampleTimer::After(), pass in 10 seconds as an argument. You don't need to use At() or Inactivity().

    When the 10 seconds is up CExampleTimer::RunL() will get called, so you need to add another call to After(10 seconds) in there to make it repeat again.

    CExampleTimer can be a member class of whatever class F1() is a member function of. You have a choice of F2() being part of the CExampleTimer class or part of the code that calls CExampleTimer, if the later then you do need MExampleTimerNotify and would use it as per the How to use this class section of the wiki.
    If you want F1() to be a member of CExampleTimer then you could put it at the start of the CExampleTimer::After() function.
    I can't tell you which is the best choice because you haven't told us the big picture about all of your code, see how having that big picture is important for the best solution? Many of the posters on here, including lots of FNC will just give you the first soltion that comes to mind, or the only one they can think of. For many design scenarios there are possiblities. Just because somebody on here posts and says you should do it such and such a way doesn't make it a) right or b) the best. There is simply lots of bad advice on here that gets posted then copied then reguritated.


    As you won't be satisfied until you're spoon fed, even though its stated clearly above, here's the code for After() and RunL()

    CExampleTimer::After(TTimeIntervalMicroSeconds32 aInterval)
    {
    F2();
    Cancel();
    iTimer.After(iStatus,aInterval);
    SetActive();
    }

    CExampleTimer::RunL()
    {
    After(10 seconds);
    }


    This solution may or may not work, you deliberatly decided not to answer any of my questions in your other thread so I can't say 100%, seeing the whole of the elephant is vitally important when active objects are being used.
    Last edited by hotcheese; 2010-05-10 at 20:53.

Similar Threads

  1. Replies: 0
    Last Post: 2009-12-07, 11:36
  2. Waiting for timer problem
    By robinbartels in forum Symbian
    Replies: 8
    Last Post: 2009-11-27, 08:41
  3. timer problem
    By plmanikandan in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-01-22, 11:20
  4. Problem in Timer Request Handling on Series60 V1.2
    By mishrasaurabh in forum Symbian
    Replies: 0
    Last Post: 2004-01-23, 06:19
  5. Problem in Timer Request Handling
    By mishrasaurabh in forum Symbian
    Replies: 0
    Last Post: 2004-01-23, 05:50

Posting Permissions

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