* 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.3 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to: Loop a Sound Playing on a Windows Form | 03/30/2017 |
|
|
ea95dd46-10a3-46c0-8263-4b205f00df7f |
How to: Loop a Sound Playing on a Windows Form
The following code example plays a sound repeatedly. When the code in the stopPlayingButton_Click event handler runs, any sound currently playing stops. If no sound is playing, nothing happens.
Example
[!code-csharpSystem.Media.SoundPlayer.PlayLooping#1] [!code-vbSystem.Media.SoundPlayer.PlayLooping#1]
Compiling the Code
This example requires:
-
References to the System and System.Windows.Forms assemblies.
-
That you replace the file name
"c:\Windows\Media\chimes.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 it 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 invalid (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.