First, drag the Destroyed event from the page onto the automation surface. Right click and select for "Wait for this event". The event will now transform into an object you can wait for.
Next, connect the Setup port to the method that will trigger the reload, in this case the PerformClick method.
Note, you must use the Setup port to ensure that OpenSpan is ready to wait for the event when you trigger it. If you call PerformClick before you enter the event block there is always the chance that the Destroyed event will fire between the two blocks in which case the event will be missed.
Finally, connect the Fired port to the blocks that should execute after the page has reloaded.
As you can see, waiting for an event is very easy in an automation, but how would you accomplish the same thing in code? You could spin your own eventing mechanism, but this would be a fair amount of work and require a good knowledge of threading. Fortunately there is another way to access the wait for event functionality. Every OpenSpan control supports a GetEvent method which takes a special EventName object. This method actually pre-dates the automation "Wait for this event" functionality. GetEvent takes a parameter of type EventName which is simply a wrapper around the name of the event. GetEvent returns an Event object which exposes a Wait method. Events objects are managed internally by the control so you do not have to worry about disposing the object. The following code snippet illustrates how to use GetEvent.
public void DoSearch()
{
// Get event
Event waitForDestroy = mSample.EventSamplePage.GetEvent(new EventName("Destroyed"));
// Perform click
mSample.Next.PerformClick();
// Wait for event
if (waitForDestroy.WaitForEvent(10000))
{
// Next steps
}
else
{
// Handle error
}
}



