diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2017-01-10 18:07:01 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-01-10 16:07:01 -0800 |
commit | f78b328759bb673b695c6b0d1a1dac6d871d257a (patch) | |
tree | 53af7ed6bce1b2287ba7addd89f782dd4606d7c6 /Xamarin.Forms.Controls.Issues | |
parent | dcea6b4853f76dbc4661c42c56244e0a70d889ed (diff) | |
download | xamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.tar.gz xamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.tar.bz2 xamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.zip |
iOS and Android timers should be runnable from any thread and execute… (#374)
* iOS and Android timers should be runnable from any thread and executed on the main thread
* removing unused Timer class declarations with minor refactoring efforts
* iOS and Android timers should be runnable from any thread and executed on the main thread
* removing bak file
* switch to v7
* add test code
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
2 files changed, 117 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28953.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28953.cs new file mode 100644 index 00000000..3a357863 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28953.cs @@ -0,0 +1,116 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System; +using System.Threading.Tasks; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 28953, "Device.StartTimer (still) behaves differently on different platforms", PlatformAffected.All)] + public class Bugzilla28953 : TestContentPage // or TestMasterDetailPage, etc ... + { + int count = 0, count2 = 0; + Label label2, label3; + bool shouldStop, shouldStop2; + + protected override void Init() + { + var stackLayout = new StackLayout + { + Orientation = StackOrientation.Vertical, + VerticalOptions = LayoutOptions.Center, + Spacing = 20 + }; + + var label1 = new Label + { + Text = "Click Start to start counting with a timer. Click Stop to reset. Both timers update text in UI thread." + }; + stackLayout.Children.Add(label1); + + label2 = new Label + { + Text = count.ToString(), + HorizontalTextAlignment = TextAlignment.Center, + }; + stackLayout.Children.Add(label2); + + label3 = new Label + { + Text = count2.ToString(), + HorizontalTextAlignment = TextAlignment.Center, + }; + stackLayout.Children.Add(label3); + + var button = new Button + { + Text = "Start" + }; + button.Clicked += Button_Clicked; + stackLayout.Children.Add(button); + + var button2 = new Button + { + Text = "Start (in background thread)" + }; + button2.Clicked += Button_Clicked2; + stackLayout.Children.Add(button2); + + Content = stackLayout; + } + + private void Button_Clicked(object sender, EventArgs e) + { + var button = sender as Button; + if (button.Text == "Start") + { + (sender as Button).Text = "Stop"; + shouldStop = false; + + Device.StartTimer(TimeSpan.FromMilliseconds(100), () => + { + label2.Text = count.ToString(); + count++; + return !shouldStop; + }); + } + else + { + button.Text = "Start"; + shouldStop = true; + count = 0; + } + } + + private void Button_Clicked2(object sender, EventArgs e) + { + var button = sender as Button; + if (button.Text == "Start (in background thread)") + { + (sender as Button).Text = "Stop (in background thread)"; + shouldStop2 = false; + + Task.Run(() => + { + Device.StartTimer(TimeSpan.FromMilliseconds(100), () => + { + label3.Text = count2.ToString(); + count2++; + return !shouldStop2; + }); + }); + } + else + { + button.Text = "Start (in background thread)"; + shouldStop2 = true; + count2 = 0; + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 36ed04cb..16a2199d 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -36,6 +36,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28570.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28796.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28939.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28953.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla29107.xaml.cs"> <DependentUpon>Bugzilla29107.xaml</DependentUpon> </Compile> |