Find out if you are using the Windows Phone Emulator

It is often useful in a Windows Phone program for the code to know whether or not it is running on a real device.  It is actually easy to do this:

  1. Add Microsoft.Phone to the references to your project if it is not already there.
  2. Put the following line at the top of your program.
    using Microsoft.Devices;
  3. You can now write code like this:
    if (Microsoft.Devices.Environment.DeviceType ==
                                                                               DeviceType.Device)
    {
        // we are running on the real phone
    }

You can use DeviceType.Emulator in the test to see if you are running on the emulator.