@borijarim wrote:
.... I have two polylines .... detect this and automatically connect them with a line ....
I don't see anything in the offerings so far to make the Line [green in your image] to connect the Polylines. Am I correct that the connecting Line does not yet exist, and needs to be drawn as part of the process?
EDIT: Maybe PEDIT / Multiple / [selection] / Join / big-fuzz-factor can serve your purpose. Here:

starting with the top situation, it does not do the middle [green line connecting as in your example], but rather does the bottom [Filleting the closer end segments of the originals]. But no code is required, and it can do multiples at once [depending on the specific geometries].

Does that work for you?
Further EDIT: You speak of multiple such situations, and want a routine to "detect this" [the gap to be filled/joined]. Post an image or sample drawing with realistic conditions. If there are multiples, by what criteria could a routine determine which ones constitute pairs that should be joined? Might a given Polyline be closer in some direction to one it should not be joined to than to the one it should be joined to? Etc.
Kent Cooper, AIA