How to safely use your time while you build a project?

So your build takes a while… How do you make use of that time (e.g. check Stack Overflow) and not forget to get back to work when the build is done? Well, you can make a sound. I am not sure if there is a simple built-in option to Visual Studio allows to play sounds on events. It is quite possible there is, but I will use what I know. I found you can play a sounds in command line by typing echo ^G, but it didn’t seem to work for me in a VS project post-build step. I blogged about using batch scripts and C# code together in a single file and here’s a way to beep from a batch script:

/* >NUL
@CALL :COMPILE_BEEP %0
@call beep.exe
@rem @DEL /q beep.exe
@GOTO :EOF

*/
class Beep
{
    static void Main(string[] args)
    {
        System.Media.SystemSounds.Asterisk.Play();
    }
}
/*
More batch code follows:

:COMPILE_BEEP
@IF EXIST beep.exe (@GOTO :EOF)
@SET WinDirNet=%WinDir%\Microsoft.NET\Framework
@IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
@IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
@IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.exe"
@%csc% /nologo /out:"beep.exe" %1
@GOTO :EOF
*/

You just put this in beep.bat and then add a beep.bat call at the end of your project post-build step (e.g. “$(ProjectDir)Scripts\Beep.bat”) and you get a beep when your project is built. But what if you also listen to something or have your volume on mute? Well, you get visual! 🙂

/* >NUL
@CALL :COMPILE_BEEP %0
@call beep.exe
@rem @DEL /q beep.exe
@GOTO :EOF

*/
using System;
using System.Drawing;
using System.Windows.Forms;

class Beep
{
    [STAThread]
    static void Main(string[] args)
    {
        System.Media.SystemSounds.Asterisk.Play();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

		var form = new Form
		{
			Text = "Build Complete!",
			FormBorderStyle = FormBorderStyle.None,
			StartPosition = FormStartPosition.CenterScreen,
			BackColor = Color.White,
			WindowState = FormWindowState.Maximized,
			TopMost = true
		};

		form.KeyDown += (s, e) => form.Close();

        var label = new Label
		{
			Dock = DockStyle.Fill,
            Font = new Font("Microsoft Sans Serif", 32F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))),
            Text = "Build Complete!",
            TextAlign = ContentAlignment.MiddleCenter,
			ForeColor = Color.Gray
		};

		label.Click += (s, e) => form.Close();

        form.Controls.Add(label);
        Application.Run(form);
    }
}
/*
More batch code follows:

:COMPILE_BEEP
@IF EXIST beep.exe (@GOTO :EOF)
@SET WinDirNet=%WinDir%\Microsoft.NET\Framework
@IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
@IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
@IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.exe"
@%csc% /nologo /out:"beep.exe" %1
@GOTO :EOF
*/

This is what you get when your build is done now:

Build Complete

Advertisements
Tagged , ,

2 thoughts on “How to safely use your time while you build a project?

  1. Keith Reichert says:

    This can also be accomplished by windows. Under “Control Panel/Sound” there is a Sounds tab. In the list, there is a Visual Studio section where you can set the sound to play for the following events: Breakpoint Hit, Build Canceled, Build Failed, Build Succeeded.

    • xyzzer says:

      Thanks, I wasn’t aware of that. Still – other than the value as a sample – I think my code is still useful because I often have my sounds muted.

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

%d bloggers like this: