How to add basic sounds to a .NET console application

We all know a couple of very annoying features of web sites: popups, flashing text, rotating images and the like. The good news is that there are some equally annoying features that you can add to .NET console applications: constantly changing titles, console window size and position, text size and colour etc.

In this short post we’ll see how to add a basic beep to a console app. As with the above mentioned features you should not overuse it.

The Console object has a Beep method which has a parameterless version:

Console.Beep();

It plays a short beep sound. If you’re not satisfied with it you can go for the overloaded Beep method that accepts a frequency in hertz and a duration in milliseconds. The lower the frequency value the deeper the sound:

Console.Beep(100, 5000);

That sounds like an organ.

Console.Beep(10000, 5000);

That on the other hand just sounds awful.

UPDATE: Saeid mentioned another way to produce sounds in console apps below in the comments section: the SystemSounds class.

View all various C# language feature related posts here.

Advertisements

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

2 Responses to How to add basic sounds to a .NET console application

  1. Saeid says:

    Also it’s possible to call
    SystemSounds.Hand.Play();
    SystemSounds.Hand.Play();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

ultimatemindsettoday

A great WordPress.com site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: