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 Form 中以非同步方式載入音效

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用狀況例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用狀況例外狀況,例如 ArgumentException ,仍會同步擲回。 如需預存的例外狀況,請參閱 所 Load() 擲回的例外狀況。

適用於

另請參閱