using System.Threading;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
+using System.Threading.Tasks;
#if UITEST
using Xamarin.UITest;
var disappeared = false;
// change margin of box after the first rendering
- new Thread(() => {
+ Task.Run(async () => {
while (true)
{
for (int margin = 20; margin < 160; margin += 20)
{
- Thread.Sleep(1000);
+ await Task.Delay(1000);
if (disappeared)
return;
Device.BeginInvokeOnMainThread(() =>
using System.Linq;
using System.Threading;
using System.Collections.Generic;
+using System.Threading.Tasks;
namespace Xamarin.Forms.Controls.Issues
{
var buttons = layout.Children.OfType<Button>();
layout.Children.Insert(0, ActionGrid(buttons.ToList()));
- PaddingAnimation(buttons).Start();
+ PaddingAnimation(buttons);
Content = layout;
}
return actionGrid;
}
- Thread PaddingAnimation(IEnumerable<Button> buttons)
+ void PaddingAnimation(IEnumerable<Button> buttons)
{
- return new Thread(() =>
+ Task.Run(async () =>
{
int increment = 1;
int current = 0;
while (true)
{
- Thread.Sleep(sleep);
+ await Task.Delay(sleep);
if (!animation)
continue;
using System.Threading;
using Xamarin.Forms.Internals;
using Xamarin.Forms.CustomAttributes;
+using System.Threading.Tasks;
#if UITEST
using Xamarin.UITest;
_abortStressTest = false;
int.TryParse(_stressTestItertionEntry.Text, out _stressTestIterationCount);
-
+
#if __UWP__
- Windows.System.Threading.ThreadPool.RunAsync(delegate { runStressTest(); });
+ Task.Run(runStressTest);
#else
ThreadPool.QueueUserWorkItem(delegate { runStressTest(); });
#endif
};
}
- void runStressTest()
+ async void runStressTest()
{
for (int i = 0; i < _stressTestIterationCount && !_abortStressTest; i++)
{
_nextStressTest.WaitOne();
while (_stressTestImage.IsLoading)
- Thread.Sleep(10);
+ await Task.Delay(10).ConfigureAwait(false);
- Thread.Sleep(10);
+ await Task.Delay(10).ConfigureAwait(false);
}
Device.BeginInvokeOnMainThread(() => {
using System.Collections.Generic;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
+using System.Threading.Tasks;
namespace Xamarin.Forms.Controls.Issues
{
var buttons = layout.Children.OfType<ImageButton>();
layout.Children.Insert(0, ActionGrid(buttons.ToList()));
- PaddingAnimation(buttons).Start();
+ PaddingAnimation(buttons);
Content = new ScrollView() { Content = layout };
}
return actionGrid;
}
- Thread PaddingAnimation(IEnumerable<ImageButton> buttons)
+ void PaddingAnimation(IEnumerable<ImageButton> buttons)
{
- return new Thread(() =>
+ Task.Run(async () =>
{
int increment = 1;
int current = 0;
while (true)
{
- Thread.Sleep(sleep);
+ await Task.Delay(sleep);
if (!animation)
continue;
using Xamarin.Forms.Internals;
using System.Collections.ObjectModel;
using System.Threading;
+using System.Threading.Tasks;
namespace Xamarin.Forms.Controls.Issues
{
var lstMessages = new ListView();
lstMessages.SetBinding(ListView.ItemsSourceProperty, ".");
- new Thread(() =>
+ Task.Run(async () =>
{
while (simulatedThreadEnabled)
{
- Thread.Sleep(500);
+ await Task.Delay(500);
if (!simulateMessages)
continue;
collection.Add(newItem);
Device.BeginInvokeOnMainThread(() => lstMessages.ScrollTo(newItem, ScrollToPosition.Start, false));
}
- }).Start();
+ });
this.Disappearing += (_, __) => simulatedThreadEnabled = false;
base.OnAppearing();
entry.Focus();
- new Thread(() =>
+ Task.Run(async () =>
{
while (!IsTested)
{
- Thread.Sleep(100);
+ await Task.Delay(100);
Device.BeginInvokeOnMainThread(() =>
{
if (entry.IsFocused)
}
});
}
- }).Start();
+ });
}
}
}
#endif
}
-}
\ No newline at end of file
+}
using System.Threading;
+using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
{
#if APP
InitializeComponent();
- new Thread(() =>
+ Task.Run(async () =>
{
- Thread.Sleep(1000);
+ await Task.Delay(1000);
SwitchIsEnabled();
- Thread.Sleep(1500);
+ await Task.Delay(1500);
SwitchIsEnabled();
- Thread.Sleep(1000);
+ await Task.Delay(1000);
SwitchIsEnabled();
- }).Start();
+ });
#endif
}
using System.Collections.Generic;
using System.Threading;
+using System.Threading.Tasks;
using Xamarin.Forms.Xaml;
namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.EmptyViewGalleries
CollectionView.ItemTemplate = ExampleTemplates.PhotoTemplate();
- new Thread(() =>
+ Task.Run(async () =>
{
- Thread.Sleep(1000);
+ await Task.Delay(1000);
Device.BeginInvokeOnMainThread(() => CollectionView.ItemsSource = new List<object>());
- Thread.Sleep(1000);
+ await Task.Delay(1000);
Device.BeginInvokeOnMainThread(() => CollectionView.ItemsSource = _demoFilteredItemSource.Items);
- }).Start();
+ });
}
}
}
\ No newline at end of file