手电筒应用程序每次都会崩溃 [英] Flashlight app crashing everytime
问题描述
我正在尝试通过Windows Phone应用程序中的TorchControl类操作手电筒应用程序:这是我的代码
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera {0} doesn't exist", desiredCamera));
}
async private void Button_Click(object sender, RoutedEventArgs e)
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = String.Empty,
VideoDeviceId = cameraID.Id
});
var videoDev = mediaDev.VideoDeviceController;
var tc = videoDev.TorchControl;
if (tc.Supported)
tc.Enabled = true;
mediaDev.Dispose();
}
但问题是每当我第二次点击按钮时应用程序崩溃。我被告知使用mediaDev.Dispose()方法,但它也无法正常工作。
But the problem is that the app crashes everytime i click on the button second time. I have been told to use the mediaDev.Dispose() method but it is also not working.
这是例外:"第一次机会异常mscorlib.ni.dll WinRT信息中出现'System.Exception'类型:找不到与此错误代码关联的文本。" - 这是在"initializeasync"中的文本中显示的。
突出显示
Here's the exception: "A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll WinRT information: The text associated with this error code could not be found." - This is showing while the text in "initializeasync" is highlighted
请帮助。谢谢
Please help. Thanks
Prajjwal Dimri
Prajjwal Dimri
推荐答案
也许使用块会有帮助。
Maybe a using block will help.
使用(var
MediaCapture ())
{
等等
}
这篇关于手电筒应用程序每次都会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!