Jaa


LightSensor.GetCurrentReading Method

Definition

Gets the current ambient-light sensor reading.

public:
 virtual LightSensorReading ^ GetCurrentReading() = GetCurrentReading;
LightSensorReading GetCurrentReading();
public LightSensorReading GetCurrentReading();
function getCurrentReading()
Public Function GetCurrentReading () As LightSensorReading

Returns

The current ambient-light sensor reading.

Examples

The following example demonstrates how a UWP app built with XAML and C# retrieves the current reading for the default light sensor.

private void DisplayCurrentReading(object sender, object args)
{
    LightSensorReading reading = _sensor.GetCurrentReading();
    if (reading != null)
    {
        ScenarioOutput_LUX.Text = String.Format("{0,5:0.00}", reading.IlluminanceInLux);
    }
}

Remarks

An application may use this method to poll the sensor for the current reading as an alternative to registering a ReadingChanged event handler. This would be the preferred alternative for an application that updates its user interface at a specific frame rate. Whether polling once or many times, the application must establish a desired ReportInterval. This informs the sensor driver that resources should be allocated to satisfy subsequent polling requests

Before using the return value from this method, the application must first check that the value is not null. (If the value is null and you attempt to retrieve it, Windows will generate an exception.)

Applies to