編輯

共用方式為


Form.ShowAsync(IWin32Window) Method

Definition

Displays the form asynchronously, by setting its Visible property to true.

[System.Diagnostics.CodeAnalysis.Experimental("WFO5002", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public System.Threading.Tasks.Task ShowAsync (System.Windows.Forms.IWin32Window? owner = default);
[<System.Diagnostics.CodeAnalysis.Experimental("WFO5002", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
member this.ShowAsync : System.Windows.Forms.IWin32Window -> System.Threading.Tasks.Task
Public Function ShowAsync (Optional owner As IWin32Window = Nothing) As Task

Parameters

owner
IWin32Window

The optional owner window that implements IWin32Window.

Returns

A Task that completes when the form is closed or disposed.

Attributes

Exceptions

The form is already visible.

-or-

The form is disabled.

-or-

The form is not a top-level form.

-or-

The form is trying to set itself as its own owner.

-or-

The form is already displayed asynchronously.

-or-

No WindowsFormsSynchronizationContext could be retrieved or installed.

-or-

The operating system is in a non-interactive mode.

The owner window is trying to set itself as its own owner.

Remarks

This method makes the form visible by setting the Visible property to true.

This method immediately returns, even if the form is large and takes a long time to be set up.

The task will complete when the form is closed or disposed.

If the owner window is provided, it ensures that the owner is topmost and sets the owner for the form.

This method also performs several checks to prevent invalid operations, such as trying to display a disabled form, attempting to display the form when it is not a top-level window, or setting the form as its own owner.

If the operating system is in a non-interactive mode, this method will throw an InvalidOperationException.

If the form is already displayed asynchronously, an InvalidOperationException will be thrown.

An InvalidOperationException will also occur if no WindowsFormsSynchronizationContext could be retrieved or installed.

There is no need to marshal the call to the UI thread manually if the call originates from a different thread than the UI-Thread. This is handled automatically.

Applies to