C# 视频刷突然冻结,不知道为什么,wp7
了解发生了什么——同时运行的加速计和视频刷将冻结视频刷。要解决此问题,请在启动视频刷之前停止加速计 使用最少的代码(如下所示),它将在应用程序启动VideoBrush后2分15秒左右可靠崩溃。这是在Windows7仿真器上,用于WindowsPhone7.5应用程序,使用c#和Xaml。如果VideoBrush stretch也设置为fill等,则会发生这种情况(这是Silverlight 1.0的一个bug) 关于我如何得出这个结论的故事,请查看下面的文字墙回答:) 为什么会发生这种情况?我不知道。可能是内存泄漏还是什么?值得注意的是,这实际上不会使应用程序本身崩溃。您不会出现任何异常 重新生成问题的代码(制作一个名为PhoneApp1的新应用程序,自己试试!):C# 视频刷突然冻结,不知道为什么,wp7,c#,silverlight,windows-phone-7,xaml,windows-phone-7.1,C#,Silverlight,Windows Phone 7,Xaml,Windows Phone 7.1,了解发生了什么——同时运行的加速计和视频刷将冻结视频刷。要解决此问题,请在启动视频刷之前停止加速计 使用最少的代码(如下所示),它将在应用程序启动VideoBrush后2分15秒左右可靠崩溃。这是在Windows7仿真器上,用于WindowsPhone7.5应用程序,使用c#和Xaml。如果VideoBrush stretch也设置为fill等,则会发生这种情况(这是Silverlight 1.0的一个bug) 关于我如何得出这个结论的故事,请查看下面的文字墙回答:) 为什么会发生这种情况?我不
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Rectangle x:Name="viewfinderCanvas" Width="480" Height="800" >
<Rectangle.Fill>
<VideoBrush x:Name="viewfinderBrush"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</phone:PhoneApplicationPage>
using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Devices;
using Microsoft.Devices.Sensors;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer AccelerometerSensor;
// Constructor
public MainPage()
{
InitializeComponent();
AccelerometerSensor = new Accelerometer();
AccelerometerStartup();
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true))
{
viewfinderCanvas.Visibility = Visibility.Visible;
var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(cam);
}
}
#region Accelerometer Startup Function
private void AccelerometerStartup()
{
try
{
if (AccelerometerSensor != null)
{
AccelerometerSensor.Start();
}
}
catch (AccelerometerFailedException)
{
}
catch (UnauthorizedAccessException)
{
}
}
#endregion
}
}
Xaml代码:
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Rectangle x:Name="viewfinderCanvas" Width="480" Height="800" >
<Rectangle.Fill>
<VideoBrush x:Name="viewfinderBrush"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</phone:PhoneApplicationPage>
using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Devices;
using Microsoft.Devices.Sensors;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer AccelerometerSensor;
// Constructor
public MainPage()
{
InitializeComponent();
AccelerometerSensor = new Accelerometer();
AccelerometerStartup();
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true))
{
viewfinderCanvas.Visibility = Visibility.Visible;
var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(cam);
}
}
#region Accelerometer Startup Function
private void AccelerometerStartup()
{
try
{
if (AccelerometerSensor != null)
{
AccelerometerSensor.Start();
}
}
catch (AccelerometerFailedException)
{
}
catch (UnauthorizedAccessException)
{
}
}
#endregion
}
}
下面的原始问题:(下面记录的代码保留,但不会重现问题,因为未连接加速计) 这是一个有趣的,我保证 我决定在我的wp7.5应用程序中放一个矩形,它的填充属性是一个视频笔刷。我使用了从一些网站上找到的代码,认为一切正常。直到我注意到摄像机的视频刷会冻结。。。运行6-40秒 我很困惑,以为我的调度计时器干扰了摄像机。对它们进行注释使其无法运行并不能解决问题。然后我尝试在应用程序中禁用我的广告。也没修好。我禁用了所有可以在整个应用程序中呈现更新的东西(计时器、调度计时器、广告旋转、任何循环),但它仍然冻结 我也做了同样的事情,甚至在读到使用设备进行调试时将设备从计算机上拔下,而使用zune open连接到计算机可能会中断工作。还是没有骰子 我创建了一个新项目,并复制粘贴了VideoBrush代码,它可以在不冻结的情况下工作 XAML代码:
<Rectangle x:Name="viewfinderCanvas" Width="480" Height="800" Visibility="Collapsed" DoubleTap="viewfinderCanvas_DoubleTap">
<Rectangle.Fill>
<VideoBrush x:Name="videoBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform x:Name="previewTransform"
CenterX=".5"
CenterY=".5" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Rectangle.Fill>
</Rectangle>
所以说真的,我不知道是什么导致了视频刷显示的冻结。我在每个函数上都设置了断点,但什么都没有发现。不存在任何错误消息。。。视频冻结了
以前有人遇到过这种情况吗?它发生在我的设备上,也发生在我编写代码的计算机上——仿真器的白框刚好停止
为了清晰起见——这只是为了显示摄像头在应用程序中看到的东西——我不是在拍照或录制视频。我只是在做这个节目。要关闭窗口,用户将双击矩形以关闭原始视图。我已经发现了发生了什么,这确实与我的代码有关 TL:DR:带有活动视频刷的活动加速计会导致视频刷最终冻结。 我做了什么来测试这个: 拿着我的2000多行代码,我坐在那里开始评论API、引用和我通常认为会导致VideoBrush冻结的东西。每次我拿出一段相当大的代码,我都会测试这个应用程序,看看它是否有什么不同。我的测试依赖于视频刷从启动到冻结需要多少秒 有趣的是,在移除任何东西之前,视频刷通常需要45秒左右才能冻结。在剪下我的代码后,我得到了我的第一个主要结果,它突然跳到了2分45秒。这是在我删除了几个网格后实现的,其中包含了几个StackPanel、TextBlock和按钮,这些都是在Blend中设置动画的 在这一点上,我幽默的想法是,我混合的东西不是从可见性开始的。从可见性到可见性。崩溃了,因此随着时间的推移,一些东西在积累。事实并非如此,因为在调用VideoBrush之前折叠所有内容的功能在2:45的冻结时间内没有产生任何变化 我拿出了我所有的资产,拿出了所有的计时器、调度计时器、秒表、日期时间实例,它仍然没有做任何改变2:45 然后我发现了它:我的加速计 对于完整的图片,我在两个不同的页面上使用wp7应用程序中的加速计。当用户第一次打开应用程序时,他将被带到一个教程页面,该页面有一个模拟主页的加速计。完成该教程后,用户将进入主页,主页上也有一个同名的加速计和eventchange通知 作为旁注,在检查我的代码时,我注意到我的一个代码错误,我没有在这两页上实际停止/处理我的加速计。这从未导致应用程序崩溃,因此也从未成为现实问题 修复后,我注意到在视频刷冻结之前,时间会跳到大约5:00。进步了,但是什么导致了这种冻结 然后,我决定在启动视频刷之前停止加速计,你瞧,视频刷在不冻结图片的情况下工作
非常抱歉,因为这是一个无法回答的问题,如果不知道什么可以阻止VideoBrush在应用程序崩溃的情况下工作。至少现在有一个已知的方法 我已经发现了发生了什么,这确实是我的代码的问题 TL:DR:带有活动视频刷的活动加速计会导致视频刷最终冻结。 我做了什么来测试这个: 拿着我的2000多行代码,我坐在那里开始评论API、引用和我通常认为会导致VideoBrush冻结的东西。每次我拿出一段相当大的代码,我都会测试这个应用程序,看看它是否有什么不同。我的测试依赖于视频刷的运行时间
using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Devices;
using Microsoft.Devices.Sensors;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer AccelerometerSensor;
// Constructor
public MainPage()
{
InitializeComponent();
AccelerometerSensor = new Accelerometer();
AccelerometerStartup();
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true))
{
viewfinderCanvas.Visibility = Visibility.Visible;
var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(cam);
}
}
#region Accelerometer Startup Function
private void AccelerometerStartup()
{
try
{
if (AccelerometerSensor != null)
{
AccelerometerSensor.Start();
}
}
catch (AccelerometerFailedException)
{
}
catch (UnauthorizedAccessException)
{
}
}
#endregion
}
}
var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
GC.Collect();
private PhotoCamera cam;
public MainPage()
{
InitializeComponent();
AccelerometerSensor = new Accelerometer();
AccelerometerSensor.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(AccelerometerSensor_CurrentValueChanged);
AccelerometerStartup();
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
viewfinderCanvas.Visibility = Visibility.Visible;
cam = new PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(cam);
}
}