1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
using System;
using Xamarin.Forms.CustomAttributes;
using System.Threading.Tasks;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 28709, "Application.Properties saving crash ")]
public class Bugzilla28709 : TestContentPage // or TestMasterDetailPage, etc ...
{
protected override void Init ()
{
var btn = new Button () {
Text = "Save Properties",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
var btn1 = new Button () {
Text = "Save Properties Multiple Threads",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
btn.Clicked += OnButtonClicked;
btn1.Clicked += (sender, e) => {
Task.Run(() => {System.Diagnostics.Debug.WriteLine ("thread 1"); OnButtonClicked1("thread1",new EventArgs());});
Task.Run(() => {System.Diagnostics.Debug.WriteLine ("thread 2"); OnButtonClicked1("thread2",new EventArgs());});
Task.Run(() => {System.Diagnostics.Debug.WriteLine ("thread 3"); OnButtonClicked1("thread3",new EventArgs());});
};
Content = new StackLayout { Children = { btn, btn1 }};
}
void OnButtonClicked (object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine ($"OnButtonClicked {sender.ToString()}");
int j = -1;
var properties = Application.Current.Properties;
int seed = 13;
while (++j < 300) {
seed = ((seed * 257) + 41) % 65536;
int i = seed % 20;
int previousClickTotal = -1;
if (properties.ContainsKey ("PreviousClickTotal" + i.ToString ()))
previousClickTotal = (int)(Application.Current.Properties ["PreviousClickTotal" + i.ToString ()]);
string clickTotal = "0";
if (properties.ContainsKey ("ClickTotal" + i.ToString ()))
clickTotal = (string)Application.Current.Properties ["ClickTotal" + i.ToString ()];
double nextClickTotal = 1.0;
if (properties.ContainsKey ("NextClickTotal" + i.ToString ()))
nextClickTotal = (double)(Application.Current.Properties ["NextClickTotal" + i.ToString ()]);
Application.Current.Properties ["PreviousClickTotal" + i.ToString ()] = ++previousClickTotal;
Application.Current.Properties ["ClickTotal" + i.ToString ()] = previousClickTotal.ToString ();
Application.Current.Properties ["NextClickTotal" + i.ToString ()] = ++nextClickTotal;
SaveAllProperties ();
}
}
async void OnButtonClicked1 (object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine ($"OnButtonClicked {sender.ToString()}");
//Application.Current.Properties[sender.ToString()] = 1;
await Application.Current.SavePropertiesAsync ();
System.Diagnostics.Debug.WriteLine ($"OnButtonClicked {sender.ToString()} done");
}
async void SaveAllProperties ()
{
await Application.Current.SavePropertiesAsync ();
}
#if UITEST
[Test]
public void Bugzilla28709Test ()
{
RunningApp.Tap (q => q.Marked ("Save Properties"));
}
#endif
}
}
|