Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:14:20+00:00 2026-06-14T15:14:20+00:00

Found out what was going on — Accelerometers and VideoBrushes running at the same

  • 0

Found out what was going on — Accelerometers and VideoBrushes running at the same time will freeze the VideoBrush. To fix this, stop the accelerometer before starting the VideoBrush

With minimal code (noted just below), it will reliably crash at around 2 minutes and 15 seconds after the VideoBrush starts on the app. This is on the Windows 7 emulator for a Windows Phone 7.5 app, using c# and Xaml. It happens if VideoBrush stretch is also set to fill, etc (there was a Silverlight 1.0 bug with this)

For the story of how I derived to this, please check out the wall of text answer below : )

Why does this happen? I do not know. Perhaps there is a memory leak or something? Of note — this actually does not crash the app itself. You will not get any exception popping up.

Code to reproduce the problem (make a new application titled PhoneApp1 and try it yourself!):

Xaml Code:

<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>

C# code:

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
    }
}

Original Question Below: (code noted below preserved, but will not reproduce problem as no accelerometer is attached)

This is a fun one, I promise.

I decided to put in my wp7.5 app a rectangle with which its fill property is a VideoBrush. I’ve used the code found from a few websites, and thought everything was all right. THis was until I noticed that the VideoBrush from the camera would freeze… anywhere from 6 – 40 seconds of running it.

Baffled, I thought my dispatch timers were interfering with the camera. Commenting them out so that they could not run did not fix the problem. I then tried disabling my ads in the app. Also didn’t fix it. I disabled everything that could render an update throughout the app (timers, dispatch timers, ad rotations, any loops) and it STILL freezes.

I did the same thing and even unplugged my device from the computer as I read debugging with the device while connected to the computer with zune open could disrupt things. Still no dice.

I created a new project and copy pasted just the VideoBrush code in, and it works without freezing.

The XAML code:

<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>

C# code:

if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true))
    {
           viewfinderCanvas.Visibility = Visibility.Visible;
           var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);

           if (Orientation == PageOrientation.PortraitUp || Orientation ==  
           PageOrientation.PortraitDown || Orientation == PageOrientation.Portrait)
             {
                videoBrush.RelativeTransform =
                new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 };
             }

           videoBrush.SetSource(cam);
    }

So truly, I have no idea what is causing this freezing of the VideoBrush display. I put breakpoints on every function and nothing picked up. No error messages exist… the video just freezes.

Has anyone encountered this before? It happens on both my device and on the computer I code from too — the emulator’s white box just stops.

for clarity — purpose of this is to just show what the camera sees in the app — I am not taking photos or recording video. I am merely making this show. To close the window, a user will double tap the rectangle to close the raw view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:14:21+00:00Added an answer on June 14, 2026 at 3:14 pm

    Thanks to your code, I was able to reproduce the issue, and I found the root cause.

    Be ready, it’s going to be a “… that’s it?” moment!

    Basically, the whole problem is on that line:

    var cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
    

    Your creating a new PhotoCamera, but you’re not keeping the reference anywhere. Therefore, when the garbage collector launches, it disposes your orphan PhotoCamera instance, thus freezing the video.

    It’s easy to reproduce: just add a button to the page, and put in the click handler:

    GC.Collect();
    

    As soon as you press the button, the video will freeze.

    Now the obvious question is: why does it freeze only with the accelerometer? Quite simple actually. A garbage collection is automatically triggered when the total number of allocated objects reaches a threshold. When you only have the video, few objects are allocated (maybe none), so the garbage collector won’t be triggered before a long time. When turning on the accelerometer, it updates its position at a high pace, allocating new objects in the process, and therefore triggering a garbage collect after a few minutes.

    How to fix the issue? Simply store your PhotoCamera reference in a property:

    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);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the same problem as Simon in this post . He found out
I was going through legacy code to fix a problem and found out that
Solved I actually found out what is going on here. Turns out it was
I was going through Wikipedia and found out that New Zealand skipped a day
I'm going to edit an ImageField using jquery ajax,after searching I found out I
I am going through the differences between Struts1 and Strust2 , i found out
I found out this morning that proc.new works in a class initialize method, but
I was going through honeybots and found out something which took me by surprise..
I'm going to be building my first mobile web app, and I found out
Stackoverflow community. I found out that WSO2 community can be contacted on this site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.