I have created a cross-platform xamarin forms app (xamarin.forms version 4.5.0.495) and run the android app using Android 10.0 (Q) and a Pixel 2 Q 10.0 - API 29 emulator.
My xaml page contains this block:
<Entry Placeholder="please enter your search query" ClearButtonVisibility="WhileEditing" Keyboard="Text" ReturnType="Search" Completed="OnSearch" > </Entry>
The code in my xaml.cs file looks like this:
`
private async void OnSearch(object sender, EventArgs e)
{
string url = ...;
string result1 = await GetAsync(url);
string result2 = Task.Run(() => GetAsync(url)).Result;
string result3 = GetAsync(url).Result;
}
private static async Task<string> GetAsync(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
return await reader.ReadToEndAsync();
}
}
`
I have hard-coded the url for debugging purposes. Moreover I am not yet allowed to post links so I have replaced the url to wikipedia with '...'. When debugging the application result1 and result2 can be obtained, however, the app is stuck thereafter and result3 can not be retrieved.
The stack trace looks as follows:
`
0xFFFFFFFFFFFFFFFF in System.Threading.Monitor.Monitor_wait C#
0x31 in System.Threading.Monitor.ObjWait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Threading/Monitor.cs:85,5 C#
0x11 in System.Threading.Monitor.Wait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/monitor.cs:218,13 C#
0x3 in System.Threading.Monitor.Wait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/threading/monitor.cs:228,13 C#
0x109 in System.Threading.ManualResetEventSlim.Wait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/shared/System/Threading/ManualResetEventSlim.cs:607,33 C#
0x30 in System.Threading.Tasks.Task.SpinThenBlockingWait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2892,25 C#
0x6C in System.Threading.Tasks.Task.InternalWait at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2832,21 C#
0x13 in System.Threading.Tasks.Task<string>.GetResultCore at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:490,31 C#
0x11 in System.Threading.Tasks.Task<string>.get_Result at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:466,19 C#
`
It looks like there might be a deadlock.
I have searched the forum for "Monitor_wait" and found this this thread and bug report:
(I am not allowed to post links yet, I hope you can find these references:)
https://forums.xamarin.com/discussion/comment/189927#Comment_189927
and
github => bugzilla-archives/40/40228/bug
I guess that my finding is related to the bug above, which has been fixed in xamarin.forms version 2.2.0-pre4. Please bear with me, as I am new to Xamarin, maybe my setup is odd or I am doing something wrong. Any kind of input is appreciated,
best regards!