I'm experiencing very strange issues while developing a WP7 app that happen usually after 30m or 1h, despite the code is really simple, almost equal to examples. The emulator does not have any problem.
app crashes with no exception being thrown
unhandled exception: {"0xffffffff"} (Yes, message is "0xffffffff". And Stacktrace is null)
once i got an exception thrown while getting DateTimeOffset.Now property (!)
UI Thread frozen, couldn't terminate app, had to power cycle the device
So at this point i think that either WP7 is really unstable or my device hardware is faulty.
Does a burn-in test exists for WP7? Like Memtest86, Prime and other utilities for the desktop?
Edit: here is the code that is causing problems:
public partial class MainPage : PhoneApplicationPage
{
private Accelerometer _accelerometer;
private GeoCoordinateWatcher _gps;
public MainPage()
{
InitializeComponent();
_accelerometer = new Accelerometer();
_accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(_accelerometer_ReadingChanged);
_accelerometer.Start();
_gps = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
_gps.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(_gps_PositionChanged);
_gps.Start();
}
void _gps_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Dispatcher.BeginInvoke(() =>
{
TBLocation.Text = e.Position.Location.ToString();
});
}
void _accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
TBAccelX.Text = string.Format("X: {0:F2} g", e.X);
TBAccelY.Text = string.Format("Y: {0:F2} g", e.Y);
});
}
}
<phone:PhoneApplicationPage
x:Class="AccelerometerTest2.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="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<StackPanel>
<TextBlock Name="TBAccelX"/>
<TextBlock Name="TBAccelY"/>
<TextBlock Name="TBLocation"/>
</StackPanel>
</phone:PhoneApplicationPage>
EDIT: As i suspected the phone was faulty. The app had run properly on another device for 5 hours.
I would suspect a memory (or resource) leak.
What does the app do?
Does the error happen while using the app or if you just leave it?
Is the app doing anything on a timer?
Have you tried monitoring memory usage over the lifetime of the app?
As there are fewer other apps and things going on in the background with the emulator, the need for the system to reclaim resources from you app is likley to be much less. It is therefore possible that such issues may not also be seen on the emulator.
If you get the latest (beta) version of the [mango] developer tools you'll be able to run your code through the new, built in profiler so you can see what is happening over time.
Related
As i have using 'AppWindow' to open separate window in xamarin forms UWP. I tried below code to open the window,
if (appWindow == null)
{
appWindow = await AppWindow.TryCreateAsync();
Frame appWindowFrame = new Frame();
appWindowFrame.Navigate(typeof(testpage));
ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowFrame);
}
await appWindow.TryShowAsync();
When 'Appwindow.TryCreateAsync' method calling, it will be thrown 'Class not registered exception'. Please see the below snippet,
I tried to check about this issue and also trying to find a solution. But i am not getting any solution to fix this. Please let me know, if you have faced same this issue or any solution to fix it.
Please make sure your testpage extend Page.
I create a blank page called AppWindowMainPage like following screenshot.
AppWindowMainPage.cs
public sealed partial class AppWindowMainPage : Page
{
public AppWindowMainPage()
{
this.InitializeComponent();
}
}
AppWindowMainPage.xaml
<Page
x:Class="App75.UWP.AppWindowMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App75.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBlock Text="test"></TextBlock>
</Grid>
</Page>
When I run the code, it could open a new window.
When debugging a fullscreen Win2d UWP app from VS and my code has an error, the app window gets frozen "always-on-top" style, forcing me to reboot or log out of windows. The app was still showing the blue startup image with no top bar access.
I tried Alt+F4, Shift+Win+Enter, Alt+Tab. The app stays fullscreen and on top even after closing it. The Win key reveals the taskbar but closing VS fails because it creates an unreachable confirmation dialog about stopping the debugger. Task manager is also unusable, hidden behind the frozen app. I've removed this line for now, but I want to start in fullscreen always.
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
Here's example code using the Win2d quick start guide that causes the problem for me:
MainPage.xaml
<Page
x:Class="Example.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Example"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<canvas:CanvasControl x:Name="canvas" Draw="canvas_Draw"/>
</Grid>
</Page>
MainPage.xaml.cs
using Microsoft.Graphics.Canvas.UI.Xaml;
using System;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls;
namespace Example
{
public sealed partial class MainPage : Page
{
public MainPage()
{
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
this.InitializeComponent();
}
private void canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
throw new Exception("error in my code");
}
}
}
I am a beginner with the Xamarin platform. I recently started developing some simple application with the sole purpose of learning the platform. I encountered a "problem". My Cross-platform app on the Android platform (I have not tested it on other platforms) consumes an unusual amount of battery.
For example, in about 2 min of use the app consumes 5% of battery where in comparison the display consumes 6%. I found out that by going into the Battery consumption page (The Android Settings). I suspect this is because I am not setting the event handlers to null (i.e. disposing of them, see the code below).
This is my xaml code:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinSample"
x:Class="XamarinSample.MainPage">
<StackLayout>
<Slider VerticalOptions="CenterAndExpand"
ValueChanged="OnSliderValueChanged"/>
<Label x:Name="valueLabel"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
Text="A Simple Label"
Font="Large"/>
<Button HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
Text="Click me!"
Clicked="OnButtonClick"/>
</StackLayout>
</ContentPage>
And this is the code-behind:
namespace XamarinSample
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
}
void OnSliderValueChanged(object sender, ValueChangedEventArgs args)
{
valueLabel.Text = args.NewValue.ToString("F3");
}
async void OnButtonClick(object sender, EventArgs args)
{
Button button = (Button)sender;
await DisplayAlert("Clicked!",
"The button labeled '" + button.Text + "' has been clicked","OK");
}
}
}
What could be the reason for this behaviour?
First do not try to analyze the battery usage of an app while debugging (or one built-in a debug configuration) as the code executed (runtime and Jit'd) will be different...
Second, you should use Google's Battery Historian for your app's battery analysis. This is a Google provided/supported Android toolset and IMHO well worth the minimal effort to set it up.
Batterystats collects battery data from your device, and Battery Historian converts that data into an HTML visualization that you can view in your Browser. Batterystats is part of the Android framework, and Battery Historian is open-sourced and available on GitHub at https://github.com/google/battery-historian.
Showing you where and how processes are drawing current from the battery.
Identifying tasks in your app that could be deferred or even removed to improve battery life.
https://developer.android.com/studio/profile/battery-historian.html
I'm developing windows universal app(XAML,C#) on phone, and am enabling accessibility for Narrator. Does anybody know how to get narrator automatically to read page title when a page is opened?
I tried setting automationproperties.name in page but didn't work:
<Page
x:Class="xxxxxx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AutomationProperties.Name="Page title to be read"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
The features of the Narrator for UWP are applied when you select a control in a list, or editing a textbox. If you want to read content when the app is opened you should use the SpeechSynthesizer API, which is really easy to implement:
1.- In XAML add a Media Element
<MediaElement x:Name="MediaElement"/>
2.-Then in the code behind of the page:
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ReadTitle();
}
private async void ReadTitle()
{
var voice = SpeechSynthesizer.AllVoices.First();
SpeechSynthesizer reader = new SpeechSynthesizer() { Voice = voice };
var text= this.GetValue(AutomationProperties.NameProperty) as String;
await reader.SynthesizeTextToStreamAsync(text);
MediaElement.SetSource(stream, stream.ContentType);
MediaElement.Play();
}
You can read everything you want passing the string to the reader.
You need to make view-able by narrator. I don't believe you can declare the Name property within the Page Class. Try something like this within the content of your Page:
<HyperlinkButton
NavigateUri="www.bing.com"
AutomationProperties.AutomationID="bing url" //Not Required to work
AutomationProperties.Name="Go to the Bing Homepage"//Narrator will read this
<StackPanel>
<TextBlock Text="Bing Dot Com" />
<TextBlock Text="www.bing.com" />
<StackPanel>
</HyperlinkButton>
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.automation.peers.accessibilityview
EDIT: You may also need to programmatically set focus on the item for this to work
I've got the Problem, that Toolkits Themes just don't wanna apply.
I've installed Silverlight RC 5, Toolkit 5 and are running in Visual Studio 2010 with a Project in Silverlight 3(doesnt offered me Silverlight 4 or higher though).
Well, I read a thousands of Tutorials but I cannot see my mistake.
I am able to use those Controls of the Toolkit properly, but the Theme...just won't apply.
Here's the code:
<UserControl x:Class="Wissensmanagement.Controls.PCategory"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:theming="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit"
xmlns:dark="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.ExpressionDark"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="625">
<Grid x:Name="LayoutRoot">
<dark:ExpressionDarkTheme>
<StackPanel HorizontalAlignment="Left">
<Button Width="60" Height="30" x:Name="btnLoad" HorizontalAlignment="Left" Content="Test" />
<controlsToolkit:Expander Header="test"/>
</StackPanel>
</dark:ExpressionDarkTheme>
</Grid>
And here is, what I See:
http://imageshack.us/photo/my-images/207/94160286.png/
If there were any hints, I would be appreciated =/
Please Check this link http://www.c-sharpcorner.com/UploadFile/mamta_m/working-with-themes-in-silverlight-toolkit-C-Sharp-based/
It will provide you some help
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
Uri uri = new Uri(#"ThemeDemo;component/Microsoft.Windows.Controls.Theming.RainierOrange.xaml", UriKind.Relative);
ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri);
ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto);
ImplicitStyleManager.Apply(LayoutRoot);
}
I hope it helps