“blinking” the interface, or chains of asynchronous calls. Periodic execution of code with a given time interval - ProcessWaiting() 1s wait handler in the form

The 1C platform provides us with the ability to asynchronously call procedures, which can sometimes be used for simple but fun things. For example, you can “blink” anything that has a color or any ability to change the visual appearance. Moreover, you can use either a simpler, but uncontrolled mechanism, or construct an interesting chain of asynchronous calls and give it the preferred behavior.

We are talking here, of course, about the ConnectWaitingHandler() procedure.

Let me remind you of the syntax of the procedure:

ConnectWaitHandler(<ИмяПроцедуры>, <Интервал>, <Однократно>)

Moreover, if you specify an interval of less than a second, the procedure must be launched once. This is where we lose control over the execution flow and lose the ability to “customize” it (flexibly, individually configure it).

But this limitation is easily overcome.

In order not to let my thoughts wander, I will immediately give a simple example and explain it.

Let's say we have a spreadsheet document on the form and we want to “blink” some area of ​​it 5 times.

/////////////////// // // “Blink” the area of ​​the Spreadsheet document 5 times, with an interval of half a second // /////////// ///////// &On the Client Procedure BlinkArea (Command) mf How Many Times to Blink = 3; // Counter. Form attribute, “visible” in wait handler procedures ConnectWaitHandler("ShowAreaSelection", 0.1, True); // You can also directly call EndProcedure &On the Client Procedure ShowArea Selection() Area = Object.TD.Area(mfFirstDataLine, mfFirstDataColumn, mfLastDataLine, mfLastDataColumn);

Border = New Line(TableDocumentCellLineType.Double);

Area.Circle(Border, Border, Border, Border); // Outline the area mfHow many times to blink = mfHow many times to blink - 1; // Decrement the counter Connect WaitHandler("RemoveArea Allocation", 0.5, True); // Connect a chain of asynchronous calls End of Procedure & On the Client Procedure Remove Area Selection() Area = Object.TD.Area(mfFirstDataLine, mfFirstDataColumn, mfLastDataLine, mfLastDataColumn);

  • Border = New Line(TableDocumentCellLineType.NoLine);
  • Area.Circle(Border, Border, Border, Border); // Remove the outline of the area If mf How Many Times to Blink > 0 Then Connect WaitHandler("Show Area Selection", 0.5, True); // Repeat as much as is left on the counter EndIf; End of Procedure
    • The only requirement is that the counter variable mfHow Many Times Blink should be “visible” from the procedures that we launch asynchronously. In this case, the variable is a form attribute.
    • An attentive reader might have noticed that with the formation of such chains we are killing two birds with one stone:
    • We bypass the restriction on the repetition of procedure calls with interval values ​​less than a second;
    • We have the ability to form chains of varying lengths and complexity:

connect the wait handler directly in the wait handler procedure itself;

make sure that such procedures connect to each other;

organize a more complex structure of call chains;<ИмяПроцедуры>, <Интервал>, <Однократно>)
endlessly complicate the variability of call management (for example, change not only their counters inside calls, but also interval values, design styles (so that the 🌈 shimmers like a rainbow).
<ИмяПроцедуры>
<Интервал>(required) Type: Number. Time interval in seconds, accurate to 1/10 of a second, after which the procedure will be called (positive number). If a value less than 1 is specified, then the value of the third parameter must be True.
<Однократно>(optional) Type: Boolean. Sign of a one-time execution of the wait handler.
True - the specified wait handler will be executed once. Default: False
Description: Connects the specified procedure as a wait handler. The procedure will be called during the system timeout period every time the specified time interval has elapsed.

Availability:
Thin client, web client, thick client.

Note:
The call to the wait handler continues until the form is closed or until the form's DisableWaitHandler method is called. Code 1C v 8.2 UE DisableWaitingHandler(<ИмяПроцедуры>)

Code 1C v 8.2 UP
&OnClient
Procedure ShellHandler()
ProcessWaiting();
End of Procedure

&On server
Procedure ProcessWaiting()
// do whatever is required
End of Procedure

//....
ConnectWaitHandler("HandlerWrapper", 3, True);

<ИмяПроцедуры>, <Интервал>, <Однократно>)
Causes a call to the specified procedure of a managed application module (a regular application module) or a global shared module at a specified time interval. The call will only be made in a “resting state,” that is, at a time when the program is not performing any actions. Calling the wait handler continues until the system shuts down or the global context's DisableWaitHandler method is called.
Code 1C v 8.x Procedure Sales ReportDay()
// ...
End of Procedure

//...
ConnectWaitingHandler("DaySalesReport", 60); // every minute
Code 1C v 8.x // In standard dynamism check. configuration updates every 20 minutes.
ConnectWaitingHandler("IB DynamicChangeCheckWaitingHandler", 20 * 60);
// connect the data exchange handler
ConnectWaitingHandler("CheckingDataExchange", chValueVariable("chNumberofSecondsPollExchange"));
ConnectWaitingHandler("Check Responses to Connection Applications", 86400); // = 24(h) * 60(min) * 60(sec) = 1 day

For Form
Code 1C v 8.x ConnectWaitingHandler(<ИмяПроцедуры>, <Интервал>, <Однократно>)
endlessly complicate the variability of call management (for example, change not only their counters inside calls, but also interval values, design styles (so that the 🌈 shimmers like a rainbow).
<ИмяПроцедуры>(required) Type: String. The name of the procedure to be connected as a wait handler.
<Интервал>(required) Type: Number. Time interval in seconds, accurate to 1/10 of a second, after which the procedure will be called (positive number). If a value less than 1 is specified, then the value of the third parameter must be True.
<Однократно>(optional) Type: Boolean. Sign of a one-time execution of the wait handler. 0True - the specified wait handler will be executed once. Default: False

Description:
Connects the specified procedure as a wait handler. The procedure will be called during the system timeout period every time the specified time interval has elapsed.

Availability:
Fat client.
Note:
The call to the wait handler continues until the form is closed or until the form's DisableWaitHandler method is called.
Example:
Code 1C v 8.x ConnectWaitingHandler("WhenWaiting", 1);
Code 1C v 8.x Form.mAutosave Interval = 300; // 5 minutes
If Form.mAutoSaveInterval<>0 Then
Form.ConnectWaitingHandler("TimerEventHandler", Int(Form.mAutoSaveInterval * 60));
endIf;

Waiting processing in the 1C:Enterprise system, as follows from the documentation, is intended for periodic execution of the global module procedure with a given time interval. The code to run will look like this:
Code 1C v 7.x Waiting Processing("UpdateCounter_",1);
Where "UpdateCounter_"- name of the global module procedure that will be launched every 1 second. (second parameter equal to 1)

But! The problem is that you can only run wait processing once. Restarting will cancel the previous one. In other words, if you want to do, for example, a timer processing to count the elapsed time, then you can only run one timer, because starting the second timer will stop the first one. But what if you need to run 2, 3 or more of these timers at the same time? Or do you still need to periodically scan the status of documents?

There is an exit! Wait processing must be run in the form context to separate this thread from the global context. And then it will become possible to periodically launch the local module procedure, i.e. procedure located in the module of your processing form.

The code to run will look like this:
Code 1C v 7.x Form.Waiting Processing("UpdateCounter_",1);
Where "UpdateCounter_"- name of the procedure of the local module of the processing form, which will be launched at intervals of 1 second. (second parameter equal to 1)
Thus, in each processing you can run your own wait processing, which will work as long as the form is open.

You can use it in forms Code 1C v 8.x Form.Waiting Processing("ProcedureName",StartTime) ,
where ProcedureName is the name of the procedure that runs after StartTime seconds
In the procedure itself, you need to insert Code 1C v 8.x Form.Waiting Processing("ProcedureName",0) to stop waiting processing (of course, after the necessary conditions are met).
Source

organize a more complex structure of call chains;<ИмяПроцедуры>, <Интервал>, <Однократно>)
endlessly complicate the variability of call management (for example, change not only their counters inside calls, but also interval values, design styles (so that the 🌈 shimmers like a rainbow).
<ИмяПроцедуры>
<Интервал>(required) Type: Number. Time interval in seconds, accurate to 1/10 of a second, after which the procedure will be called (positive number). If a value less than 1 is specified, then the value of the third parameter must be True.
<Однократно>(optional) Type: Boolean. Sign of a one-time execution of the wait handler.
True - the specified wait handler will be executed once. Default: False
Description: Connects the specified procedure as a wait handler. The procedure will be called during the system timeout period every time the specified time interval has elapsed.

Availability:
Thin client, web client, thick client.

Note:
The call to the wait handler continues until the form is closed or until the form's DisableWaitHandler method is called. Code 1C v 8.2 UE DisableWaitingHandler(<ИмяПроцедуры>)

Code 1C v 8.2 UP
&OnClient
Procedure ShellHandler()
ProcessWaiting();
End of Procedure

&On server
Procedure ProcessWaiting()
// do whatever is required
End of Procedure

//....
ConnectWaitHandler("HandlerWrapper", 3, True);

<ИмяПроцедуры>, <Интервал>, <Однократно>)
Causes a call to the specified procedure of a managed application module (a regular application module) or a global shared module at a specified time interval. The call will only be made in a “resting state,” that is, at a time when the program is not performing any actions. Calling the wait handler continues until the system shuts down or the global context's DisableWaitHandler method is called.
Code 1C v 8.x Procedure Sales ReportDay()
// ...
End of Procedure

//...
ConnectWaitingHandler("DaySalesReport", 60); // every minute
Code 1C v 8.x // In standard dynamism check. configuration updates every 20 minutes.
ConnectWaitingHandler("IB DynamicChangeCheckWaitingHandler", 20 * 60);
// connect the data exchange handler
ConnectWaitingHandler("CheckingDataExchange", chValueVariable("chNumberofSecondsPollExchange"));
ConnectWaitingHandler("Check Responses to Connection Applications", 86400); // = 24(h) * 60(min) * 60(sec) = 1 day

For Form
Code 1C v 8.x ConnectWaitingHandler(<ИмяПроцедуры>, <Интервал>, <Однократно>)
endlessly complicate the variability of call management (for example, change not only their counters inside calls, but also interval values, design styles (so that the 🌈 shimmers like a rainbow).
<ИмяПроцедуры>(required) Type: String. The name of the procedure to be connected as a wait handler.
<Интервал>(required) Type: Number. Time interval in seconds, accurate to 1/10 of a second, after which the procedure will be called (positive number). If a value less than 1 is specified, then the value of the third parameter must be True.
<Однократно>(optional) Type: Boolean. Sign of a one-time execution of the wait handler. 0True - the specified wait handler will be executed once. Default: False

Description:
Connects the specified procedure as a wait handler. The procedure will be called during the system timeout period every time the specified time interval has elapsed.

Availability:
Fat client.
Note:
The call to the wait handler continues until the form is closed or until the form's DisableWaitHandler method is called.
Example:
Code 1C v 8.x ConnectWaitingHandler("WhenWaiting", 1);
Code 1C v 8.x Form.mAutosave Interval = 300; // 5 minutes
If Form.mAutoSaveInterval<>0 Then
Form.ConnectWaitingHandler("TimerEventHandler", Int(Form.mAutoSaveInterval * 60));
endIf;

Waiting processing in the 1C:Enterprise system, as follows from the documentation, is intended for periodic execution of the global module procedure with a given time interval. The code to run will look like this:
Code 1C v 7.x Waiting Processing("UpdateCounter_",1);
Where "UpdateCounter_"- name of the global module procedure that will be launched every 1 second. (second parameter equal to 1)

But! The problem is that you can only run wait processing once. Restarting will cancel the previous one. In other words, if you want to do, for example, a timer processing to count the elapsed time, then you can only run one timer, because starting the second timer will stop the first one. But what if you need to run 2, 3 or more of these timers at the same time? Or do you still need to periodically scan the status of documents?

There is an exit! Wait processing must be run in the form context to separate this thread from the global context. And then it will become possible to periodically launch the local module procedure, i.e. procedure located in the module of your processing form.

The code to run will look like this:
Code 1C v 7.x Form.Waiting Processing("UpdateCounter_",1);
Where "UpdateCounter_"- name of the procedure of the local module of the processing form, which will be launched at intervals of 1 second. (second parameter equal to 1)
Thus, in each processing you can run your own wait processing, which will work as long as the form is open.

You can use it in forms Code 1C v 8.x Form.Waiting Processing("ProcedureName",StartTime) ,
where ProcedureName is the name of the procedure that runs after StartTime seconds
In the procedure itself, you need to insert Code 1C v 8.x Form.Waiting Processing("ProcedureName",0) to stop waiting processing (of course, after the necessary conditions are met).
Source