Runs a given modal session, as defined in a previous invocation of
- macOS 10.0+
A pointer to the modal session structure returned by the
beginmethod for the window to be displayed.
An integer indicating the reason that this method returned. See the discussion for a description of possible return values.
A loop that uses this method is similar in some ways to a modal event loop run with
run, except with this method your code can do some additional work between method invocations. When you invoke this method, events for the
NSWindow object of this session are dispatched as normal. This method returns when there are no more events. You must invoke this method frequently enough in your loop that the window remains responsive to events. However, you should not invoke this method in a tight loop because it returns immediately if there are no events, and consequently you could end up polling for events rather than blocking.
Typically, you use this method in situations where you want to do some additional processing on the current thread while the modal loop runs. For example, while processing a large data set, you might want to use a modal dialog to display progress and give the user a chance to cancel the operation. If you want to display a modal dialog and do not need to do any additional work in parallel, use
run instead. When there are no pending events, that method waits idly instead of consuming CPU time.
The following code shows a sample loop you can use in your code:
If the modal session was not stopped, this method returns
NSModal. At this point, your app can do some work before the next invocation of
run (as indicated in the example’s
do call). If
stop was invoked as the result of event processing,
stop was invoked, this method returns the value passed to
abort was invoked, this method returns
The window is placed on the screen and made key as a result of the
run message. Do not send a separate