Thursday, July 11, 2013

Windows Phone Tip: Check if App is Running on Emulator

There are times where you want to check if your app is running on the emulator. For example, Bluetooth functionality can only be tested on a real device. Hence, in your code you could check to see if the app is running on an emulator. If it is, then terminate the app.

The following code snippet checks for the current device type. If it is running on an emulator, terminate the app:

//---check if your app is running on the emulator---
if (Microsoft.Devices.Environment.DeviceType ==
    MessageBox.Show("Running on emulator!");
    //---terminate the app---

No comments: