Share via


SoundPlayer.LoadAsync 方法

定义

使用新线程从流或 Web 资源中加载 .wav 文件。

public:
 void LoadAsync();
public void LoadAsync ();
member this.LoadAsync : unit -> unit
Public Sub LoadAsync ()

例外

加载所用的时间超出了 LoadTimeout 指定的时间(以毫秒为单位)。

找不到 SoundLocation 指定的文件。

示例

下面的代码示例演示如何使用 LoadAsync 方法异步加载 .wav 文件以供 类的 SoundPlayer 实例使用。 此代码示例是为 SoundPlayer 类提供的一个更大示例的一部分。

try
{
   
   // Assign the selected file's path to 
   // the SoundPlayer object.  
   player->SoundLocation = this->filepathTextbox->Text;
   
   // Load the .wav file.
   player->LoadAsync();
}
catch ( Exception^ ex ) 
{
   ReportStatus( ex->Message );
}
try
{
    // Assign the selected file's path to 
    // the SoundPlayer object.  
    player.SoundLocation = this.filepathTextbox.Text;

    // Load the .wav file.
    player.LoadAsync();
}
catch (Exception ex)
{
    ReportStatus(ex.Message);
}
Try
    ' Assign the selected file's path to the SoundPlayer object.
    player.SoundLocation = Me.filepathTextbox.Text

    ' Load the .wav file.
    player.LoadAsync()
Catch ex As Exception
    ReportStatus(ex.Message)
End Try

注解

SoundPlayer如果将 配置为从 Stream 或 Web 资源加载 .wav 文件,则此方法将使用新线程从位置开始加载 .wav 文件。

即使加载不成功,此方法也会 LoadCompleted 在加载完成时引发 事件。

SoundPlayer如果将 配置为从本地文件路径加载 .wav 文件,则此方法不执行任何操作,因为加载将延迟到开始播放。

有关异步加载的详细信息,请参阅 如何:在 Windows 窗体中异步加载声音

此方法将存储在任务中,它返回该方法的同步对应项可能引发的所有非使用异常。 如果异常存储在返回的任务中,则在等待任务时将引发该异常。 使用异常(如 ArgumentException)仍会同步引发。 有关存储的异常,请参阅 引发的 Load()异常。

适用于

另请参阅