Jump to content

Notification between two processes


ning
 Share

Recommended Posts

Hello,

So I'm writing a program split into two halves - one downloads photos from Flickr while the other half displays them in a window, updating when there's a new one available. (I've set it up like this because the user interface wasn't responsive enough when it was trying to do both things at once.)

Is there a good way of getting one half to send a notification to the other half? A simple 'ping' would suffice; there's some information to send but that could be placed in a file. The only thing I've come up with so far is a hidden window with a couple of buttons that can be clicked. The trouble is, this doesn't seem to work when the window is hidden (GuiSetState (@SW_HIDE)), so I resorted to placing it beyond the edge of the screen. Still appears in the taskbar though.

I don't want to have to poll a file or registry entry every so often. Is there a way of doing this with GuiRegisterMsg or something?

cheers

ben

Link to comment
Share on other sites

  • Moderators

Try setting a HotKeySet() in the file you want to Receive the information, to start doing whatever it needs to do, and with the script that needs to send the information, make it Send() the Hotkey when it needs to for the appropriate function in the 2nd script.

1st script

;Do something

;Done something

Send('{End}')

2nd script

HotKeySet('{End}', 'StartThis')

While 1

Sleep(100000)

Wend

Func StartThis()

;Do what you need to do

EndFunc

Others may say use Consolewrite, but I've found the above method useful.

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

I'm not saying ConsoleWrite, but if I did I'd say it like this... :lmao:

Parent IPC script:

; ipc-parent.au3
; Console I/O IPC example script by Dave Fulgham
; GUI portion generated by AutoBuilder 0.5 Prototype. Go CyberSlug.

#include <GuiConstants.au3>

GuiCreate("IPC Parent", 291, 182,(@DesktopWidth-291)/2, (@DesktopHeight/2)-182 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Edit_1 = GuiCtrlCreateEdit("", 0, 0, 290, 150)
$Button_2 = GuiCtrlCreateButton("Quit", 100, 152, 80, 30)

GuiSetState()

$ourChild = Run(@ScriptDir & "\ipc-child.exe", @ScriptDir, @SW_SHOW, 2)
If $ourChild Then
    GUICtrlSetData($Edit_1, "Started child process." & @CRLF & "Listening for updates..." & @CRLF)
EndIf

While 1
    If StdoutRead($ourChild, 0, 1) Then
        StdoutRead($ourChild)
        GUICtrlSetData($Edit_1, "Child said something happened!" & @CRLF, 1)
    EndIf
    $msg = GuiGetMsg()
    Select
    Case ($msg = $GUI_EVENT_CLOSE) Or ($msg = $Button_2)
        ProcessClose($ourChild)
        ExitLoop
    Case Else
       ;;;
    EndSelect
WEnd
Exit

Child IPC script (compile before testing):

; ipc-child.au3 (COMPILE TO EXE BEFORE TESTING!!)
; Console I/O IPC example script by Dave Fulgham
; GUI portion generated by AutoBuilder 0.5 Prototype by CyberSlug

#include <GuiConstants.au3>

GuiCreate("IPC Child", 211, 40,(@DesktopWidth-211)/2, (@DesktopHeight/2) + 40 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Button_1 = GuiCtrlCreateButton("Something Happened!", 0, 5, 140, 30)
$Button_2 = GuiCtrlCreateButton("Quit", 140, 5, 70, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case ($msg = $GUI_EVENT_CLOSE) Or ($msg = $Button_2)
        ExitLoop
    Case $msg = $Button_1
        ConsoleWrite("Something happened.")
    Case Else
       ;;;
    EndSelect
WEnd
Exit

HotkeySet method is pretty clever, BTW, but for-sure you'd want to use a key combo that the user wouldn't normally enter.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

  • Moderators

HotkeySet method is pretty clever, BTW, but for-sure you'd want to use a key combo that the user wouldn't normally enter.

I agree, but I was just making it easy for them to understand... Consolewrite is probably the right answer, I just haven't bothered to look into it to understand the StderrRead/StdinWrite/StdoutRead , and since I don't have to pass information back and forth to each application, my method is quick and dirty.

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

Thanks everyone.

SmOke_N: That's interesting, I hadn't thought of that. I'll have a think and see if I can come up with an obscure key code. One that wasn't even on the standard keyboard would be useful (there must be 'expansion' keycodes - can we use those? I'm thinking like HotKeySet ("{0xFF}") or something like that).

DaveF: Nice example. I didn't really want to be 'polling' something in a loop, but I guess something has to at some point, and that's a pretty elegant solution.

Skruge: My understanding of the dummy control was that it would only work within one script. You create a dummy control, and then use GUICtrlSendToDummy within that script for a notification. Does it work if you call it from another script?

One thing I know is possible in Linux is sending 'signals' to running processes, for example telling them to quit, restart or of some kind of OS error. There are also a couple of user-defined ones. Is there some equivalent to this in Windows?

cheers

ben

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...