Jump to content

Coordinating 2 Running Scripts


Recommended Posts

I am running many scripts concurrently each controlling its own window. Everytime when a script decides that it needs to send out some command it will do this:

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

; do some checking here

The problem is after one script has issued WinActivate($mywin), it should not be preempted by Windows before its processing is completed. That is, the few lines above should be treated as one atomic unit. So, locking is required.

$tmpSocket= -1

While $tmpSocket = -1

$tmpSocket=TCPListen("127.0.0.1", 65432)

WEnd

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

TCPCloseSocket($tmpSocket)

I know at anytime Windows only allows one process listening to a port and so by obtaining a socket on a port. I achieve some sort of locking. But, is there a better and more natural way to achieve locking similar to my codes above.

Link to comment
Share on other sites

I am running many scripts concurrently each controlling its own window. Everytime when a script decides that it needs to send out some command it will do this:

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

; do some checking here

The problem is after one script has issued WinActivate($mywin), it should not be preempted by Windows before its processing is completed. That is, the few lines above should be treated as one atomic unit. So, locking is required.

$tmpSocket= -1

While $tmpSocket = -1

$tmpSocket=TCPListen("127.0.0.1", 65432)

WEnd

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

TCPCloseSocket($tmpSocket)

I know at anytime Windows only allows one process listening to a port and so by obtaining a socket on a port. I achieve some sort of locking. But, is there a better and more natural way to achieve locking similar to my codes above.

if it is about the $mywin issue then all script should have the following line:

if not winactive ($mywin) then WinActivate($mywin)
else don't do enything.....

I hope I understood what you watned to achieve here.

Link to comment
Share on other sites

I am running many scripts concurrently each controlling its own window. Everytime when a script decides that it needs to send out some command it will do this:

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

; do some checking here

The problem is after one script has issued WinActivate($mywin), it should not be preempted by Windows before its processing is completed. That is, the few lines above should be treated as one atomic unit. So, locking is required.

$tmpSocket= -1

While $tmpSocket = -1

$tmpSocket=TCPListen("127.0.0.1", 65432)

WEnd

WinActivate($mywin)

WinWaitActive($mywin)

Send(...)

Sleep(2000) ; wait for the result to return

TCPCloseSocket($tmpSocket)

I know at anytime Windows only allows one process listening to a port and so by obtaining a socket on a port. I achieve some sort of locking. But, is there a better and more natural way to achieve locking similar to my codes above.

Sounds to me like your best solution would be to use ControlSend which can send to a non active window, or to use messages which are more versatile, more reliable and very much faster.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I cannot use ControlSend() since the target window don't have control (is it possible to ControlSend() to a target window?). So I have to activate the window first and use regular Send (and also mouseclick()). And in that case, when 2 copies of my script is running concurrently, it is possible that after my first copy has issued a WinActivate(), my second copy also issue its own WinActivate(). So, while my first copy thinks its window is active and starts sending it keystroke, it is actually my second copy's window been activated and receiving the keystroke.

Link to comment
Share on other sites

I cannot use ControlSend() since the target window don't have control (is it possible to ControlSend() to a target window?). So I have to activate the window first and use regular Send (and also mouseclick()). And in that case, when 2 copies of my script is running concurrently, it is possible that after my first copy has issued a WinActivate(), my second copy also issue its own WinActivate(). So, while my first copy thinks its window is active and starts sending it keystroke, it is actually my second copy's window been activated and receiving the keystroke.

FRom the help file

ControlSend works in a similar way to Send but it can send key strokes directly to a window/control, rather than just to the active window.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It does show control id, and control classname(both which are supported by the ControlSend command)

Wrong.

3d windows doesn't always (or never?) have a control, use "" for the class name/id parameter in such cases.

Edited by FreeFry
Link to comment
Share on other sites

  • Moderators

It does show control id, and control classname(both which are supported by the ControlSend command)

I'm curious on how you "know" that "his" au3info is showing a control ID and a ClassNameNN... :) (psychic?)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well doesn't all windows have to have a control in them? otherwise they would have no.. content? correct me if im wrong

Edit:

I was going to add that if there was no class name/id then he could just use "" for that parameter, but I wanted to wait for his response first. :)

Edit2:

Hmm, just tried it on a 3d window, and it has no control. :/ My fault sorry for the miss guiding info I guess. Still the "" for the class name/id parameter should work.

Edited by FreeFry
Link to comment
Share on other sites

  • Moderators

Well doesn't all windows have to have a control in them? otherwise they would have no.. content? correct me if im wrong

Edit:

I was going to add that if there was no class name/id then he could just use "" for that parameter, but I wanted to wait for his response first. :)

GUICreate("")
GUISetState()
While GUIGetMsg() <> -3
Wend
You could answer your own question there :) .

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Yeah, I'm aware of that, but is there ever a window? Kinda stupid example if you ask me.. I was assuming that the window would actually have something in it.

In any case, I was wrong about this, 3d windows doesn't seem to have a control.

A stupid example? ... Do you even know what a control is?

Regardless, your logic is flawed and you are thinking a tad bit inside the box. However, you probably provided a viable solution by leaving the parameter blank all the same.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

A stupid example? ... Do you even know what a control is?

Regardless, your logic is flawed and you are thinking a tad bit inside the box. However, you probably provided a viable solution by leaving the parameter blank all the same.

Yes, your example was stupid imo. I'm very aware that a window doesn't need to have a control.

My assumption that his game window would have a control, was falsely based on that it would have a control to contain the rendering area, but I was wrong about that.

I'm sorry if I offended your flawless logic I guess. :)

Link to comment
Share on other sites

  • Moderators

Yes, your example was stupid imo. I'm very aware that a window doesn't need to have a control.

My assumption that his game window would have a control, was falsely based on that it would have a control to contain the rendering area, but I was wrong about that.

I'm sorry if I offended your flawless logic I guess. :)

No need to apologize, we can't all know what we are doing at all times :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...