omron — Executing/Switching the Background Task

About This Application will not execute this thread continuously for more than 20ms, because the operating system TimeSlice time period is set to 20ms. When the operating system is not executing the Viewer thread, the CPU can execute any other thread or remain idle (if there are no other active threads to execute). Remember, the IWS Period and TimeSlice parameters were created to prevent all threads from being active at the same time to prevent 100% CPU usage. During thread execution, the thread must handle its pending messages. For example, the Viewer module must update any related screen objects.

If there are no messages pending, the thread deactivates itself and gives control back to the operating system. The operating system immediately switches to the next active thread. In other words, a thread can interrupt its own execution — even if the operating system TimeSlice time period has not yet expired (which occurs frequently in real-world applications). Note: The Database Spy , DDE Server , LogWin , and ODBC Runtime modules do not have a TimeSlice parameter. Consequently, after each thread handles all of its pending messages, the threads become inactive until the next Period message for each one of the threads occurs.

The Background Task is the exception to the execution/switching process just discussed. The mechanism for executing/switching the Background Task is described in the next section. Executing/Switching the Background Task The Background Task executes scripts from the Math and Scheduler worksheets (for example, messages from Alarm and Trend worksheets). In addition, the Background Task executes all Recipe and Report commands when the Recipe() or Report() functions are executed during the runtime. Although the Alarm , Math , Scheduler , and Trend tasks are not threads, you can specify or change their Period time in the Program Settings.ini file located in the IWS program directory.

The Period default values (in milliseconds) are as follows: [Period] Math=100 Sched=50 Alarm=100 Trend=1000 These values mean that every 100ms, IWS generates a Period message to the Math task. Every 50ms, IWS generates a Period message to the Scheduler task, and so on. Caution: We strongly recommend that you do not modify the Background Task default values unless it is absolutely necessary. Configuring any of these parameters incorrectly can cause your entire system to malfunction (for example, CPU usage will go to 100%) and/or cause some tasks to perform poorly.

If you must change the parameter defaults, note the values before making your changes so if a malfunction occurs you can return to the original settings. Keep in mind that the Background Task thread has the same priority as other threads in IWS ( Drivers , Viewer , and so forth), which means that the operating system will not execute this task continuously for more than 20ms. The Background Task executes the Recipe and Report worksheets when the Recipe and Report functions are called, respectively.

Because the Recipe() and Report() functions are synchronous , once the Background Task starts executing the functions, it will not switch to another task ( Alarm , Math , Scheduler , or Trend ) until it completely executes the functions. Executing a Recipe() or Report() function usually takes a few milliseconds. The Background Task must switch between the Alarm , Math , Scheduler , and Trend tasks. When Background Task switches to the Scheduler task, it will not switch to another task ( Alarm , Math , or Trend ) until all Scheduler worksheets are executed.

After executing all Scheduler worksheets, the Background Task will not execute the Scheduler again until it receives the next Period message for the Scheduler task. The Background Task applies the same behavior when executing the Alarm and Trend tasks — when the Background Task switches to the Alarm or Trend task, it will not switch to another task until it handles all pending messages. So, the Background Task will not execute the Alarm or Trend task again, until IWS generates the next Period message for each of these tasks. The Background Task typically executes the Alarm , Scheduler , and Trend tasks in a few milliseconds.

However, it can take longer to execute the Math task because it usually contains loops and complex Page 24 InduSoft Web Studio