Hello Robert,
The problem is caused by the fact that your application is not recognized as Open. Try increasing the "Open Applications | General | Method invoke timeout" project setting (set its value to more than 20000 ms) and see whether this solves the problem. To learn more about the options, see the "Project Properties - General Open Applications Options" help topic.
If this does not help, I can suggest that you try the following workaround script. This script waits until the main form object ('MainForm') gets a valid 'WinFormsObject' name and returns this object.
[VBScript]
Function getMainForm()
' The default timeout is 60 seconds
timeout = 60000
Set proc = Sys.Process(<ProcessName>)
Set mainForm = Utils.CreateStubObject
oldTimeout = Options.OpenApps.InvokeTimeout
endTime = GetTickCount + timeout
Do While GetTickCount < endTime
Set mainForm = proc.WaitWinFormsObject("MainForm", 0)
If mainForm.Exists Then
Exit Do
End If
Delay 200
' This line resets the object tree
Options.OpenApps.InvokeTimeout = Options.OpenApps.InvokeTimeout + 1
Loop
Options.OpenApps.InvokeTimeout = oldTimeout
If mainForm.Exists = False Then
Log.Warning "Unable to get the main form object."
End If
Set getMainForm = mainForm
End Function