I have Click activity that clicks/invokes ‘Refersh Data’ button, that - in its turn - retrieves data from database and puts these data into some grid and also emits custom Windows event, just posts this event.
I am using Delphi code for emitting/posting event:
uses
SysUtils, Windows;
procedure EmitRPAActivityCompletedEvent;
implementation
//GPT
procedure EmitRPAActivityCompletedEvent;
var
hEvent: THandle;
begin
// Create an event with a unique name
hEvent := CreateEvent(nil, True, False, 'MyApp_ActivityCompletedEvent');
if hEvent = 0 then
raise Exception.Create('Failed to create the event');
try
// Set the event to signaled state
SetEvent(hEvent);
finally
// Close the event handle
CloseHandle(hEvent);
end;
end;
And I just want to monitor for this event, catch this even in my UiPath workflow as unambigous evidence that my workflow can continue execution. Something like ‘Wait for’ activity if there was such activity.
GPT suggested me to use ‘Invoke Code’ activity with C# code:
using System.Runtime.InteropServices;
using System.Threading;
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
public void WaitForCustomEvent()
{
// Open the event by its unique name
IntPtr hEvent = CreateEvent(IntPtr.Zero, false, false, "MyApp_ActivityCompletedEvent");
if (hEvent != IntPtr.Zero)
{
// Wait for the event to be signaled, with a timeout (in milliseconds)
WaitForSingleObject(hEvent, 60000); // E.g. 60 seconds timeout
}
}
But this code does not compile even I am pasting the body only in the ‘Code’ Field and event after I have added necessary workspaces to ‘Imports’ of the workflow.
So, ‘Invoke Code’ is not appropriate. I have tried ‘Trigger Scope’ and ‘Triggers’, but I see no way to indicate that my triggers should listen to some Windows event.