我试图运行在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()方法,但它也不起作用。 这里的例外:
类型的第一个机会异常“System.Exception的”发生在 mscorlib.ni.dll WinRT的信息:与此错误 代码关联的文本无法被发现。
而在文本 “initializeasync” 突出显示
请帮助这是显示。谢谢。使用默认值(即不改变
SynchronizationContext
)调用await
将继续在另一个线程的方法,一些东西,并不总是由图形和媒体库支持(我亲眼:
什么是例外? – Sievajet
“mscorlib.ni.dll中发生第一次机会异常类型'System.Exception' WinRT信息:无法找到与此错误代码关联的文本。” - 当“initializeasync”中的文本突出显示时显示 – Prajjwal
请考虑编辑帖子以介绍这些详细信息。 – theMayer