Control method and device for realizing timed task execution in program, processor and computer readable storage medium thereof

By setting user interface or Socket instructions in the program, using timers and task lists to manage timing tasks, the problem of inconvenience in the prior art of timed tasks is solved, and easy and on-time task execution is achieved.

CN119597415APending Publication Date: 2025-03-11TRANSCOM INSTR
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411459733.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

The prior art is difficult to achieve convenient, fast and easy-to-operate tasks in programs, especially when manpower is limited, and tasks cannot be executed in sequence or timely manner in chronological order.

Method used

Set tasks through the user interface or Socket instructions, use the timer to find tasks that reach the start time, and sort the tasks according to the start time, create a "not executed", "executing" and "completed" task list, rewrite the timer to eliminate errors, and cancel errors or exception tasks.

Benefits of technology

It realizes easy and on-time execution of relevant processes, meets the needs of timely execution of tasks, and improves the convenience and accuracy of operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597415A_ABST
    Figure CN119597415A_ABST
Patent Text Reader

Abstract

The invention relates to a control method for realizing timed task execution in a program. The control method comprises the following steps: setting a task through a user interface or a Socket instruction; starting to execute the task; arranging the starting time of the task queue according to a time sequence; searching the task reaching the starting time at regular time through a timer; the timer is rewritten to eliminate the error. The invention also relates to a device for realizing timed task execution, a processor and a computer readable storage medium thereof. By means of the control method and device for achieving the task execution in the program, the processor and the computer readable storage medium, the process executed in a period of time in the future can be planned and executed in sequence according to the time sequence, so that the related process is executed easily and punctually, and the actual production requirement is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of program development, and in particular to the field of timed execution of tasks, and specifically refers to a control method, device, processor and computer-readable storage medium for implementing timed execution of tasks in a program. Background Art

[0002] According to actual application requirements, during the use of the program, considering the limited manpower, it is impossible to operate the program during rest time, and to avoid frequent manual use and setting of the program. It is impossible to execute in chronological order or perform tasks at a scheduled time, which is very inconvenient. Summary of the invention

[0003] The purpose of the present invention is to overcome the shortcomings of the above-mentioned prior art and to provide a control method, device, processor and computer-readable storage medium for implementing timed execution of tasks in a program that is convenient, fast, easy to operate and has a wide range of applications.

[0004] In order to achieve the above-mentioned purpose, the control method, device, processor and computer-readable storage medium for implementing the timed execution of tasks in the program of the present invention are as follows:

[0005] The control method for implementing the timed execution of tasks in the program has the following main features:

[0006] (1) Set the task through the user interface or Socket command;

[0007] (2) Start executing the task;

[0008] (3) Arrange the start time of the task queue in chronological order;

[0009] (4) Use a timer to periodically search for tasks that have reached their start time, store tasks that have not yet started to be executed in the "unexecuted" task list in ascending order of start time, add tasks that are being executed to the "executing" task list, and add completed tasks to the "completed" task list;

[0010] (5) Rewrite the timer to eliminate the error;

[0011] (6) If a task is incorrectly formulated or a system anomaly is detected, the task being executed is canceled and the timer is turned off.

[0012] Preferably, the task of setting the setting through the user interface in step (1) is specifically:

[0013] User interface settings: Set up the corresponding task list according to requirements.

[0014] Preferably, the step (2) of setting the task through the Socket instruction specifically includes the following steps:

[0015] (1-1.1) Send instructions according to user needs through Socket instructions;

[0016] (1-1.2) Parse the corresponding tasks according to the instructions sent by the Socket command;

[0017] (1-1.3) Add the parsed task to the task queue and wait for the user to confirm the task start.

[0018] Preferably, the step (3) specifically includes the following steps:

[0019] Convert the start time in the task queue into seconds and sort them in ascending order.

[0020] Preferably, the step (4) specifically includes the following steps:

[0021] (4.1) Before starting a task, check whether the previous task is in progress. If so, cancel the previous task; otherwise, continue with step (4.2);

[0022] (4.2) Create three task lists, namely "Completed", "In Progress" and "Not Executed";

[0023] (4.3) Determine whether the task has not started. If so, store the task list in the "unexecuted" task list in ascending order of start time; if the task reaches the start time, execute the task and add the executing task to the "executing" task list;

[0024] (4.4) After the task is executed, add the task to the "Completed" task list.

[0025] Preferably, the step (5) specifically includes the following steps:

[0026] (5.1) Rewrite the timer newTimer. When the timer newTimer starts, the timer startTime will be used to obtain the exact time.

[0027] (5.2) Get the current precise time currentTime;

[0028] (5.3) If the correction count tickCount is 0 and the absolute value of currentTime-startTime is less than 100, continue with step (6); otherwise, continue with step (5.4);

[0029] (5.4) If the absolute value of currentTime-(startTime+(tickCount+1)×1000) is less than 100, then the value of tickCount is increased by 1; if the correction count tickCount can be divided by the timing interval interval, then the scheduled task check is performed; if a task reaches the start time, then it is executed; otherwise, wait for the next check.

[0030] The main feature of the device for realizing the control of timing execution of tasks in a program is that the device comprises:

[0031] a processor configured to execute computer executable instructions;

[0032] The memory stores one or more computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the control method for timing execution of tasks in the above program are implemented.

[0033] The main feature of the processor for implementing the control of timed execution of tasks in a program is that the processor is configured to execute computer executable instructions, and when the computer executable instructions are executed by the processor, the various steps of the control method for implementing timed execution of tasks in the above-mentioned program are implemented.

[0034] The main feature of the computer-readable storage medium is that a computer program is stored thereon, and the computer program can be executed by a processor to implement the various steps of the control method for implementing the timed execution of tasks in the above-mentioned program.

[0035] The control method, device, processor and computer-readable storage medium for implementing scheduled execution of tasks in the program of the present invention can plan the processes to be executed in a period of time in the future and execute them in chronological order, so as to achieve easy and timely execution of related processes and realize actual production needs. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 The present invention is a flowchart of a control method for implementing a timed execution task in a program of the present invention. DETAILED DESCRIPTION

[0037] In order to more clearly describe the technical content of the present invention, further description is given below in conjunction with specific embodiments.

[0038] The control method for implementing the timed execution of tasks in the program of the present invention comprises the following steps:

[0039] (1) Set the task through the user interface or Socket command;

[0040] (2) Start executing the task;

[0041] (3) Arrange the start time of the task queue in chronological order;

[0042] (4) Use a timer to periodically search for tasks that have reached their start time, store tasks that have not yet started to be executed in the "unexecuted" task list in ascending order of start time, add tasks that are being executed to the "executing" task list, and add completed tasks to the "completed" task list;

[0043] (5) Rewrite the timer to eliminate the error;

[0044] (6) If a task is incorrectly formulated or a system anomaly is detected, the task being executed is canceled and the timer is turned off.

[0045] As a preferred embodiment of the present invention, the step (1) of setting the task through the user interface is specifically as follows:

[0046] User interface settings: Set up the corresponding task list according to requirements.

[0047] As a preferred embodiment of the present invention, the step (2) of setting the task through the Socket instruction specifically includes the following steps:

[0048] (1-1.1) Send instructions according to user needs through Socket instructions;

[0049] (1-1.2) Parse the corresponding tasks according to the instructions sent by the Socket command;

[0050] (1-1.3) Add the parsed task to the task queue and wait for the user to confirm the task start.

[0051] As a preferred embodiment of the present invention, the step (3) specifically comprises the following steps:

[0052] Convert the start time in the task queue into seconds and sort them in ascending order.

[0053] As a preferred embodiment of the present invention, the step (4) specifically comprises the following steps:

[0054] (4.1) Before starting a task, check whether the previous task is in progress. If so, cancel the previous task; otherwise, continue with step (4.2);

[0055] (4.2) Create three task lists, namely "Completed", "In Progress" and "Not Executed";

[0056] (4.3) Determine whether the task has not started. If so, store the task list in the "unexecuted" task list in ascending order of start time; if the task reaches the start time, execute the task and add the executing task to the "executing" task list;

[0057] (4.4) After the task is executed, add the task to the "Completed" task list.

[0058] As a preferred embodiment of the present invention, the step (5) specifically comprises the following steps:

[0059] (5.1) Rewrite the timer newTimer. When the timer newTimer starts, the timer startTime will be used to obtain the exact time.

[0060] (5.2) Get the current precise time currentTime;

[0061] (5.3) If the correction count tickCount is 0 and the absolute value of currentTime-startTime is less than 100, continue with step (6); otherwise, continue with step (5.4);

[0062] (5.4) If the absolute value of currentTime-(startTime+(tickCount+1)×1000) is less than 100, then the value of tickCount is increased by 1; if the correction count tickCount can be divided by the timing interval interval, then the scheduled task check is performed; if a task reaches the start time, then it is executed; otherwise, wait for the next check.

[0063] The device for implementing control of timing execution of tasks in a program of the present invention, wherein the device comprises:

[0064] a processor configured to execute computer executable instructions;

[0065] The memory stores one or more computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the control method for timing execution of tasks in the above program are implemented.

[0066] The processor of the present invention is used to implement the control of timed execution of tasks in a program, wherein the processor is configured to execute computer executable instructions, and when the computer executable instructions are executed by the processor, the various steps of the control method for implementing timed execution of tasks in the above-mentioned program are implemented.

[0067] The computer-readable storage medium of the present invention stores a computer program thereon, and the computer program can be executed by a processor to implement the various steps of the control method for implementing the timed execution of tasks in the above-mentioned program.

[0068] In a specific implementation of the present invention, in order to meet the above-mentioned production needs, a method for executing tasks at a scheduled time in a program is provided.

[0069] The technical solution adopted by the method is to parse the tasks set by the user interface or the instructions sent through the Socket to generate tasks in order of time, and execute the corresponding task when the execution time of a task is reached.

[0070] Compared with the existing method, this method provides two methods: user interface setting and socket instruction setting.

[0071] The user interface settings can set the corresponding task list according to the user's own needs. Considering the convenience and speed of the settings, this behavior is suitable for scenarios with a small number of tasks.

[0072] The socket instruction setting can parse the task according to the instruction sent by the user, add it to the task queue, and wait for the user to confirm the task start. This behavior is suitable for scenarios with a large number of tasks and corresponding task instructions. In addition, it also provides an operation to cancel the task execution so that users can handle exceptions found during the task execution in a timely manner.

[0073] Timing is achieved through a timer. Since the timer has errors and the errors accumulate with the number of timings, the later the task starts, the greater the error. This method corrects the error caused by the timer and controls the error within 100ms. However, this method also has certain defects, that is, since it is impossible to determine the preparation time for the task itself to process data, the execution result of the task has a certain delay. The timing here is the time point when a complete task starts.

[0074] The present invention specifically comprises the following steps:

[0075] 1. Prerequisites:

[0076] The minimum time resolution is 1 second, and the start time of different tasks cannot be the same.

[0077] 2. Mission:

[0078] Contains the start time and specific operation procedures.

[0079] 3. Task Queue:

[0080] Task collection.

[0081] 4. Socket command:

[0082] The determined instruction format can be converted into the corresponding task after successful parsing.

[0083] 5. Start:

[0084] Confirm the execution.

[0085] 6. Arrange in chronological order:

[0086] Convert the start time in the task queue into seconds and sort them in ascending order.

[0087] 7. Scheduled execution:

[0088] Before starting a task, check whether there is a previous task in progress. If so, cancel it.

[0089] Use a timer to periodically search for tasks that have reached their start time. When there are a large number of tasks, this search will take a lot of time, so you can create three task lists, namely "Completed", "In Progress", and "Not Executed".

[0090] When all tasks have not started execution, these tasks need to be stored in the "unexecuted" task list according to the original task list, according to the start time from the smallest to the largest. Since the tasks in the "unfinished" task list are already sorted by time, each timer can only check whether the first task in the "unexecuted" task list has reached the start time. Once the start time is reached, this task will be executed and added to the "executing" task list.

[0091] When the task is completed, it needs to be added to the "Completed" task list.

[0092] 8. Eliminate errors:

[0093] The C# timer has errors during use. This error is not fixed and will increase as the number of timer times increases. Therefore, once the number of times is too large, the error will become larger. In order to ensure the accuracy of the task start time, the timer needs to be rewritten.

[0094] The rewritten timer includes timer timer (timing interval 100 milliseconds), timing interval interval (unit: second), start timing time startTime (unit: millisecond) and correction count tickCount (default 0).

[0095] The rewritten timer newTimer, when newTimer starts, startTime gets the exact time:

[0096] startTime=TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMitllisecods

[0097] The Elapsed of the timer in newTimer is triggered when the interval is reached. The following operations need to be performed when it is triggered:

[0098] (1) Get the current accurate time:

[0099] currentTime=TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds

[0100] (2) If tickCount is equal to 0 and the absolute value of currentTime-startTime is less than 100, skip the following steps.

[0101] (3) If the absolute value of currentTime-(startTime+(tickCount+1)×1000) is less than 100, tickCount is increased by 1. If tickCount is divisible by interval, the scheduled task check is performed. If a task has reached the start time, it is executed. If not, wait for the next check.

[0102] 9. Cancellation:

[0103] If the user makes a mistake in task formulation or finds a system anomaly, and the scheduled task execution has already started, an operation to cancel the task execution is required. Scheduled task cancellation not only cancels the task being executed, but also turns off the timer to prevent the unexecuted task from automatically executing when the start time arrives. In this method, the execution of scheduled tasks is achieved through asynchronous operations. A new Task is created and the task execution is canceled through the cancellation operation of CancellationTokenSource.

[0104] The technical solution of the present invention implements the execution task through a timer, and it is inferred from the description that it is not related to the timer, and a loop method is used, which consumes CPU performance. Secondly, the acquisition of system time in the technical solution of the present invention is not only to determine the time when the task starts to execute, but also to eliminate the error of the timer and ensure the accuracy of the start execution time.

[0105] The technical solution of the present invention is different from the prior art in the way of judging whether a task is executed. The technical solution of the present invention is a timer to obtain a task. The technical solution of the present invention has a low CPU occupancy rate and relatively high performance. The creativity lies in the error elimination of the timer. As time goes by during the use of the timer, the error will become larger and larger. The technical solution of the present invention controls the error within 100ms by comparing it with the system time and using an algorithm.

[0106] The specific implementation scheme of this embodiment can refer to the relevant description in the above embodiment, which will not be repeated here.

[0107] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.

[0108] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.

[0109] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.

[0110] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution device. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0111] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the corresponding program may be stored in a computer-readable storage medium, which, when executed, includes one of the steps of the method embodiment or a combination thereof.

[0112] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0113] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.

[0114] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0115] The control method, device, processor and computer-readable storage medium for implementing scheduled execution of tasks in the program of the present invention can plan the processes to be executed in a period of time in the future and execute them in chronological order, so as to achieve easy and timely execution of related processes and realize actual production needs.

[0116] In this specification, the present invention has been described with reference to specific embodiments thereof. However, it is apparent that various modifications and variations may be made without departing from the spirit and scope of the present invention. Therefore, the specification and drawings should be regarded as illustrative rather than restrictive.

Claims

1. A control method for implementing timed execution of tasks in a program, characterized in that: The method comprises the following steps: (1) Set the task through the user interface or Socket command; (2) Start executing the task; (3) Arrange the start time of the task queue in chronological order; (4) Use a timer to periodically search for tasks that have reached their start time, store tasks that have not yet started to be executed in the "unexecuted" task list in ascending order of start time, add tasks that are being executed to the "executing" task list, and add completed tasks to the "completed" task list; (5) Rewrite the timer to eliminate the error; (6) If a task is incorrectly formulated or a system anomaly is detected, the task being executed is canceled and the timer is turned off.

2. The control method for implementing timed execution of tasks in a program according to claim 1, characterized in that: The specific steps of setting the task through the user interface in step (1) are as follows: User interface settings: Set up the corresponding task list according to requirements.

3. The control method for implementing timed execution of tasks in a program according to claim 1, characterized in that: The step (2) of setting the task through the Socket instruction specifically includes the following steps: (1-1.1) Send instructions according to user needs through Socket instructions; (1-1.2) Parse the corresponding tasks according to the instructions sent by the Socket command; (1-1.3) Add the parsed task to the task queue and wait for the user to confirm the task start.

4. The control method for implementing timed execution of tasks in a program according to claim 1, characterized in that: The step (3) specifically comprises the following steps: Convert the start time in the task queue into seconds and sort them in ascending order.

5. The control method for implementing timed execution of tasks in a program according to claim 1, characterized in that: The step (4) specifically comprises the following steps: (4.1) Before starting a task, check whether the previous task is in progress. If so, cancel the previous task; otherwise, continue with step (4.2); (4.2) Create three task lists, namely "Completed", "In Progress" and "Not Executed"; (4.3) Determine whether the task has not started. If so, store the task list in the "unexecuted" task list in ascending order of start time; if the task reaches the start time, execute the task and add the executing task to the "executing" task list; (4.4) After the task is executed, add the task to the "Completed" task list.

6. The control method for implementing timed execution of tasks in a program according to claim 1, characterized in that: The step (5) specifically comprises the following steps: (5.1) Rewrite the timer newTimer. When the timer newTimer starts, the timer startTime will be used to obtain the exact time. (5.2) Get the current precise time currentTime; (5.3) If the correction count tickCount is 0 and the absolute value of currentTime-startTime is less than 100, continue with step (6); otherwise, continue with step (5.4); (5.4) If the absolute value of currentTime-(startTime+(tickCount+1)×1000) is less than 100, then the value of tickCount is increased by 1; if the correction count tickCount can be divided by the timing interval interval, then the scheduled task check is performed; if a task reaches the start time, then it is executed; otherwise, wait for the next check.

7. A device for implementing control of timed execution of tasks in a program, characterized in that: The device comprises: a processor configured to execute computer executable instructions; A memory storing one or more computer executable instructions, wherein when the computer executable instructions are executed by the processor, the steps of the control method for implementing the timed execution of tasks in the program described in any one of claims 1 to 6 are implemented.

8. A processor for implementing control of timed execution of tasks in a program, characterized in that: The processor is configured to execute computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the control method for implementing the timed execution of tasks in the program described in any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program can be executed by a processor to implement the various steps of the control method for implementing the timed execution of tasks in any one of the programs of claims 1 to 6.