【发布时间】:2015-01-10 15:52:37
【问题描述】:
我正在尝试通过 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”中的文本高亮显示时显示
【问题讨论】:
-
有什么异常?
-
“在 mscorlib.ni.dll WinRT 信息中出现了“System.Exception”类型的第一次机会异常:找不到与此错误代码关联的文本。 - 当“initializeasync”中的文本突出显示时显示
-
考虑编辑帖子以介绍这些细节。
-
你确定在调用“dispose”之后第二次按钮点击完成了吗?
标签: c# .net dispose flashlight