SoundPlayer.LoadAsync 方法

定义

使用新线程从流或 Web 资源中加载 .wav 文件。Loads a .wav file from a stream or a Web resource using a new thread.

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

例外

加载所用的时间超出了 LoadTimeout 指定的时间(以毫秒为单位)。The elapsed time during loading exceeds the time, in milliseconds, specified by LoadTimeout.

找不到 SoundLocation 指定的文件。The file specified by SoundLocation cannot be found.

示例

下面的代码示例演示如何使用 LoadAsync 方法以异步方式加载 .wav 文件以供类的实例使用 SoundPlayerThe following code example demonstrates the use of the LoadAsync method to asynchronously load a .wav file for use by an instance of the SoundPlayer class. 此代码示例是为类提供的更大示例的一部分 SoundPlayerThis code example is part of a larger example provided for the SoundPlayer class.

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 文件。If a SoundPlayer is configured to load a .wav file from a Stream or Web resource, this method begins loading a .wav file from the location using a new thread.

此方法 LoadCompleted 在加载完成时引发事件,即使加载未成功。This method raises the LoadCompleted event when loading completes, even if the load was not successful.

如果将 SoundPlayer 配置为从本地文件路径加载 .wav 文件,则此方法不执行任何操作,因为加载会推迟到开始播放。If a SoundPlayer is configured to load a .wav file from a local file path, this method does nothing, because loading is deferred until playing begins.

有关异步加载的详细信息,请参阅 如何:在 Windows 窗体内异步加载声音For more information about asynchronous loading, see How to: Load a Sound Asynchronously within a Windows Form.

适用于

另请参阅