Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-loop-a-sound-playing-on-a-windows-form.md
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.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
csharp
vb
sound loops
SoundPlayer class [Windows Forms], play looping
sounds [Windows Forms], looping
playing sounds [Windows Forms], looping
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:

.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