Announcement

Collapse
No announcement yet.

loop every x seconds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • loop every x seconds

    I have a simple program that loads data from an external file and displays it in a listview.

    I want it to refresh the information every 10 seconds by calling a function called loadInfo() every 10 seconds after the single dialog window loads.

    How do I do that? I tried putting it in the callback function but that doesn't work.

    This seems like it should be simple to do.

  • #2
    Use SetTimer() and process WM_TIMER notification message.

    Example here:
    GUI + Worker Thread + Abort Demo 11-24-07

    You may as well run the "get data from file" in a separate thread of execution, but its not necessary. That demo includes on-screen clock, which is basically the "proof" that the screen is getting refreshed.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      What about TimeSetEvent
      Rgds, Dave

      Comment


      • #4
        >What about TimeSetEvent

        What about a Waitable Timer? Waitable Timer Object Demo June 2005

        Lots of ways to do it. For that matter, LOOP on TIME$ can be made to work, but that would not only be ugly, it would earn negative panache points.

        BUT..... why are we checking file contents on a timer in the first place? Seems to me we should be looking for a change in the file.
        PowerBASIC and related source code. Please do not post questions or discussions, just source code.


        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Thanks everybody,

          SetTimer() and WM_TIMER worked perfectly.

          I couldn't get TimeSetEvent to work, it caused a GPF.

          Comment


          • #6
            Well, since SetTimer()/WM_TIMER is working this may not be that important but...

            >TimeSetEvent to work, it caused a GPF.

            No, TimeSetEvent did not cause the GPF. The cause would be "programmer error."

            It sounds like you are fairly new to programming with PB for Windows; and if you are a refugee from "Visual Anything" you probably have limited exposure to direct calls to the Windows' API.

            However, the WinAPI is bug-free except AFAIK for GetPrivateProfileSection() on Windows/9x. (It's fine after that). (The error? it has an 'off by one' error in the return value).

            FWIW, TimeSetEvent is the long way tp do what you want to do. SetTimer()/WM_TIMER is a much better fit.


            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              No, TimeSetEvent did not cause the GPF. The cause would be "programmer error."
              Ha! yes clearly. I certainly didn't mean to imply that the function itself was faulty. Maybe I should of said "My program causes a GPF when I try to use timeSetEvent".

              It sounds like you are fairly new to programming with PB for Windows; and if you are a refugee from "Visual Anything" you probably have limited exposure to direct calls to the Windows' API.
              At least with PBWIN. I do a lot with PBCC (probably 90% of what I do) for CGI but callbacks and API functions are relatively rare for me. I get the gist of it but just don't do it enough to have it down smoothly. Usually a point in the right direction and I can figure it out. Since I've started using PB, about 9 years ago, I've done maybe 10 PBWIN programs total but hundreds of PBCC, mostly CGI.

              Comment


              • #8
                'Michael's code compiles fine in PBWin8. Trying to figure out why not with PBWIN9?
                PowerBASIC and related source code. Please do not post questions or discussions, just source code.


                The cookie demo seems a bit hard to follow. It might be nice to pull out the required code.


                Code:
                'Syntax PBWin8 THREAD CREATE ProcName (param) [SUSPEND] TO hThread  'compiles fine PBWIN8
                'Syntax PBWin9 THREAD CREATE FuncName (param) [StackSize,] [SUSPEND] TO hThread  'TO missing PBWIN9
                THREAD CREATE WorkerThreadFunction (CBHNDL) SUSPEND TO hThread
                Last edited by Mike Doty; 27 Aug 2008, 11:55 PM.
                The world is full of apathy, but who cares?

                Comment


                • #9
                  >Trying to figure out why not with PBWIN9?
                  Referenced code:
                  Code:
                  Compiler: PowerBASIC Inc PB/Windows version 7.02
                  Haven't tried 9x myself, but I have to believe you still get a message from the compiler if it finds something it doesn't like. Message not shown.

                  The cookie demo?
                  Code:
                  Author: Michael Mattias, Racine WI April, 2001  using PB/DLL v 6.0
                  I code better now. Deal with it.
                  -- OR --
                  Do a 'find' here on FindFirstChangeNotification. I'm pretty sure others have created applications using these synchronization objects.

                  Generic comments re "old demos" not compiling with new version(s) of compiler:
                  This whine's time has come
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    It was shown above (scrolls off screen)

                    'Syntax PBWin9 THREAD CREATE FuncName (param) [StackSize,] [SUSPEND] TO hThread 'TO missing PBWIN9

                    Good morning, Michael.
                    Here is another whine.
                    Why is the width of these code windows so small? Could the BBS software increase the width a bit, please.
                    Last edited by Mike Doty; 28 Aug 2008, 07:33 AM.
                    The world is full of apathy, but who cares?

                    Comment


                    • #11
                      FWIW, on the cookie demo (which really is not that different from some of my other demos), this one leaps out at me...
                      Code:
                      IF hFind <> %Invalid_HANDLE_VALUE THEN
                      In the current compilers and version of Win32API.INC, this will ALWAYS be true, since hFind is declared as a LONG and %INVALID_HANDLE_VALUE is defined as &hFFFFFFFF??? (a DWORD)... 6x would have found equality when hFind = -1&, but 7x+ would not.

                      I'll bet there's all kinds of LONG/DWORD mismatches in that code; and who knows what other things I would find were I inclined to do so.

                      But... maybe some ambitious person will update that to 8x or 9x and post it as a "reply" to the original. (What a great idea for one of those people who ask for project ideas!)

                      Then again, this may just be one of those cases where Mr. Zale has a very large smile on his face: Everyone has become 'DDT-Dependent' and a simple little SDK-style program sends them scurrying back to mama.

                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Code:
                        'Syntax PBWin9 THREAD CREATE FuncName (param) [StackSize,] [SUSPEND] TO hThread 'TO missing PBWIN9
                        Oh, "TO missing" is the error message?

                        Well my eyes are not what they used be but I sure as hell can see "TO hThread" in
                        Code:
                        THREAD CREATE WorkerThreadFunction (CBHNDL) SUSPEND TO hThread
                        Call me crazy, but this sounds like a compiler bug just begging to be properly reported.

                        Try putting a comma before SUSPEND and see what happens.


                        MCM
                        Last edited by Michael Mattias; 28 Aug 2008, 07:46 AM.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          My eyes went out last night trying to figure it out.
                          The world is full of apathy, but who cares?

                          Comment


                          • #14
                            MCM
                            In the current compilers and version of Win32API.INC, this will ALWAYS be true, since hFind is declared as a LONG and %INVALID_HANDLE_VALUE is defined as &hFFFFFFFF??? (a DWORD)... 6x would have found equality when hFind = -1&, but 7x+ would not.
                            Did you not already do one??? (or close to it) that did something along the lines of (If outside of range then cycle back to in range)
                            I KNOOOOOWWWWWW it has to be hidden in your libraries somewhere (and yes I know when not used often its hard to find)...I saw it somewhere in the forums, and everytime I look to find it...danged if I can.

                            Unfortunately the only hint of a clue I have is it had a line of if some value add &HFFFF to it....but the idea is clear as mud so I may not be describing correctly
                            Engineer's Motto: If it aint broke take it apart and fix it

                            "If at 1st you don't succeed... call it version 1.0"

                            "Half of Programming is coding"....."The other 90% is DEBUGGING"

                            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                            Comment


                            • #15
                              I mostly use now

                              Code:
                              #INCLUDE "WIN32API.INC"
                              %INVALID_HANDLE_VALUE_LONG = -1& 
                              
                              ...
                                LOCAL hFind AS LONG
                               .....
                                IF hFind <> %INVALID_HANDLE_VALUE_LONG THEN
                              Then there's always the MACRO Tom Hanlin came up with:
                              Code:
                              MACRO eq32 (a,b) = BITS???(a) = BITS???(b) 
                              
                              ... 
                                  IF Eq32 (hFind, %INVALID_HANDLE_VALUE)  THEN  ' 32bit compare of LONG with DWORD
                              MCM
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment

                              Working...
                              X