Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-load-a-sound-asynchronously-within-a-windows-form.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Load a Sound Asynchronously within a Windows Form 03/30/2017
csharp
vb
SoundPlayer class [Windows Forms], loading sounds asynchronously
sounds [Windows Forms], loading on separate threads
threading [Windows Forms], sounds
3b6a9296-1d5e-4d52-a4ba-94366d6fe302

How to: Load a Sound Asynchronously within a Windows Form

The following code example asynchronously loads a sound from an URL and then plays it on a new thread.

Example

[!code-csharpSystem.Media.SoundPlayer.LoadAsync#1] [!code-vbSystem.Media.SoundPlayer.LoadAsync#1]

Compiling the Code

This example requires:

  • References to the System and System.Windows.Forms assemblies.

  • That you replace the file name "http://www.tailspintoys.com/sounds/stop.wav" with a valid file name.

Robust Programming

File operations should be enclosed within appropriate exception-handling blocks.

The following conditions may cause an exception:

.NET Framework Security

Do not make decisions about the contents of the file based on the name of the file. For example, the file Form1.vb may not be a Visual Basic source file. Verify all inputs before using the data in your application.

See also