* 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
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 |
|
|
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:
-
The path name is malformed. For example, it contains characters that are not valid or is only white space (xref:System.ArgumentException class).
-
The path is read-only (xref:System.IO.IOException class).
-
The path name is
Nothing(xref:System.ArgumentNullException class). -
The path name is too long (xref:System.IO.PathTooLongException class).
-
The path is not valid (xref:System.IO.DirectoryNotFoundException class).
-
The path is only a colon ":" (xref:System.NotSupportedException class).
.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.