12 Replies Latest reply on Feb 2, 2017 11:13 AM by duncanbaker

    OnTimer script consuming CPU cycles


      Hey folks


      I have a situation where we have a robot machine generating PDFs. It's the classic scenario where an OnTimer script step starts and the machine checks for records that need a PDF making, if it finds some then it proceeds to do that, if not it ends and the process starts again 60 seconds later. The search happens very quickly. It is a hosted file.


      What's happening is that CPU cycles on the robot machine are being consumed even when the script is not running. The CPU percentage slowly climbs the longer that the file is open running this OnTimer routine. If left for a couple days, FileMaker becomes unresponsive and I have to crash out. And even more than that, if I close the file and have no files open, FileMaker continues to consume the CPU cycles. I've put some screenshots below with explanatory text. This has been tested on multiple robot machines and with the file hosted on different servers and the same occurs.


      Now I have set up a new file with an OnTimer and done something very simple (Enter Find Mode then Enter Browse Mode), and this does not exhibit the same behavior. That would point to the routine in my problem file but if a script is not running then why would any CPU cycles be used, and if the file is closed then surely no cycles should be used? (I appreciate that occasional polling might result in a few but not maxing out a core.)


      I'd appreciate any thoughts anyone has one this. Many thanks.


      This is the file open. Debugger is on and you can see no script is running. FileMaker is consuming 28%. The file is not actually doing anything here.



      The file has been closed, I've waited a few minutes. You can see no files are open. CPU is still humming away.



      Then I close FileMaker and reopen it. No files open and the CPU is at zero - what one would expect.



      So then I open the file again and it starts off at 0% when it's not running the script. The OnTimer has been triggered OnOpen.



      And after a few minutes the CPU starts climbing again even though there's no script running. Give it a few hours and we're back to maxing out the core.


        • 1. Re: OnTimer script consuming CPU cycles

          Weird.  I don't think I've heard that one before.


          A couple of thoughts:

          - there are different ways to generate PDFs on the server through iText.  That would save you from having to keep a robot machine.  A google for "iText FileMaker" should turn up a good number of resources


          - keeping a robot machine, you could adopt different ways of triggering the script without having to use OnTimer

          -- here's a native FM approach: ClickWorks | Trigger a script on another client , this would allow the PDF creation to be run on-demand

          -- use FM's ActiveX API and us a Windows Task schedule to run the script on a schedule.

          • 2. Re: OnTimer script consuming CPU cycles

            This sounds like something to report as a bug. I recommend clicking "home" above and then using the link provided to add an Issue Report on this. That will bring it to the attention of FileMaker TS staff who can then pass it on to the developers if it is something that they do not yet know about.

            • 3. Re: OnTimer script consuming CPU cycles

              Many thanks wimdecorte for the alternative ideas. I'll check those out.

              • 4. Re: OnTimer script consuming CPU cycles

                Thanks philmodjunk. Yeah, that was going to be my next step if this wasn't a known issue. I'll go ahead and get that submitted.

                • 5. Re: OnTimer script consuming CPU cycles

                  For anyone else looking at this in the future, another idea for a workaround is to close FileMaker on a regular basis and reopen it again. This will clear FM using the CPU cycles and start fresh. It could be done every hour or whatever is needed. There may be a number of approaches to automate this, but one idea is to have a FM script:

                  • Launch a .bat file that has a pause in it for 10 secs or so
                  • Close FileMaker using Exit Application
                  • .bat is still ticking through its 10 secs
                  • When it gets to the end of that 10 secs it opens a launcher file that gets the robot functions up and running


                  I don't have a sample of that to hand but if anyone needs help with it, reach out.

                  • 6. Re: OnTimer script consuming CPU cycles

                    That's what the FM ActiveX API is for, it can launch and quit FM and is more elegant than the batch file approach with a launcher.  But that'll work too of course

                    • 7. Re: OnTimer script consuming CPU cycles

                      You can even create and execute a batch file from FileMaker so you could export the Batch file so that the timer starts ticking down and then close FileMaker....

                      • 8. Re: OnTimer script consuming CPU cycles

                        This is how one little question turns into a world of discovery!


                        Wim, if you have a simple example of how to use the ActiveX API, I'd be very interested. It's not something I have explored before. Either a small script that opens a file or triggers a script or something. Or perhaps some resources that are FM specific that you could point me to?


                        Please though, only if you have a moment and it's a quick thing to do - I'm sure you have plenty of things going on. Many thanks.

                        • 9. Re: OnTimer script consuming CPU cycles
                          Set FMProApp = CreateObject ("FMPRO.Application")
                          Set FMProDocs = FMProApp.Documents
                          FMProApp.Visible = True
                          Set FMProDoc = FMDocs.Open("c:\TestFile.fmp12","","")
                          FMProDoc.DoFMScript ("TestScript")


                          This is what it would look like in a VBscript.  It would also work with some modification in PowerShell.

                          Line 1 will launch FM if it is not running and will hook into FM if it is

                          To close FM when done you would just call:





                          All methods and properties:

                          ActiveX Automation objects, methods, and properties (Windows)

                          • 10. Re: OnTimer script consuming CPU cycles

                            And yeah this is interesting too. I think what you mean by this (and to expand for future readers) is something along the lines of:

                            • Create a table with a single text field
                            • Create a new record in this table and enter the first line of the batch file
                            • Add additional records for each line in the batch file that are required
                            • Export these records (selecting to export only the single text field) as a Tab Separated Text File setting the extension as .bat
                            • Run the .bat using Send Event script step


                            All great ideas. Thanks Phil.

                            • 11. Re: OnTimer script consuming CPU cycles

                              That's a simplied approach of what I use for other purposes (such as mounting shared folders to a specific drive letter).


                              But I have a few more wrinkles, details:


                              I use more than one field with a calculation field that concatenates them into the text field that I export. I thus can use one of those fields to specify parameters for the command lines from data from a script or database field. Another field identifies the batch field for a given batch file so that I can create a "library" of the same and perform a find to execute a particular batch.


                              I specify the option to open the file automatically so that exporting also executes the batch.


                              And I export to the temporary folder to avoid cluttering the computer's drive with my batch files.

                              • 12. Re: OnTimer script consuming CPU cycles

                                Fascinating stuff. I was going to start doing my taxes this weekend, but now I'll probably start playing with this! Thanks for giving me an excuse to put that task off (again)!


                                Thanks to you and philmodjunk for your time and generosity this morning. A great thread that hopefully others find useful. The issue report for the original problem has been submitted and we'll see where that leads.