PostEvent()

Syntax

Result = PostEvent(Event [, Window, Object [, Type [, Data]]])
Description
Posts an event at the end of the internal event queue.

Parameters

Event The event to post. For a list of PureBasic event, see WindowEvent(). When using custom event, the first value must be at least #PB_Event_FirstCustomValue, to not clash with internal events.
Window (optional) The window number associated with the event. When using a custom event, it can be any integer number. This value can be retrieved with EventWindow().
Object (optional) The object number associated with the event. It can be for example a gadget or menu number. When using a custom event, it can be any positive integer number (zero included). This value can be retrieved with EventGadget().
Type (optional) The type associated with the event. When using custom event, the first value must be at least #PB_EventType_FirstCustomValue, to not clash with internal values. This value can be retrieved with EventType().
Data (optional) A data associated with the event. It is only valid when using a custom event and can be any integer number. This value can be retrieved with EventData().

Return value

Returns a non-zero value if the event was sent without error, zero otherwise.

Remarks

This command can be very useful to communicate between threads and the main event loop. For example, a thread can send a custom event when it has finished its processing (with an associated data), so the main loop will get it and further processing can be done.
  ; All our custom events
  Enumeration #PB_Event_FirstCustomValue
    #EventBeginProcessing
    #EventProcessingFinished
  EndEnumeration
  
  
  Procedure Thread(Value)
    PostEvent(#EventBeginProcessing)
    
    Delay(3000)
    PostEvent(#EventProcessingFinished)
  EndProcedure
  
  OpenWindow(0, 200, 200, 100, 100, "PostEvent")
  
  CreateThread(@Thread(), 0)
  
  Repeat
    Event = WaitWindowEvent()
    
    Select Event
      Case #EventBeginProcessing
        Debug "Thread begin processing "
        
      Case #EventProcessingFinished
        Debug "Thread processing finished"
    EndSelect
    
  Until Event = #PB_Event_CloseWindow

See Also

WindowEvent(), EventWindow(), EventGadget(), EventType(), EventData()

Supported OS

All

<- OpenWindow() - Window Index - RemoveKeyboardShortcut() ->