Maui for android editor control issue
Hello all. my app move massive amount of text to the editor and this freeze the app for a while is there a way to handle this move so the app not freeze. Thank you.
Developer technologies | .NET | .NET MAUI
-
Anonymous
2023-12-01T05:40:40.4266667+00:00 How did you move massive amounts of text? Using copy-paste function or reading text from the local text file, etc?
Which platform is not working when moving massive amount of text to the editor?
Please share your .NET version.
As note: Guidelines for posting a quality question on Microsoft Q&A
-
Haviv Elbsz • 2,111 Reputation points
2023-12-01T11:09:34.1466667+00:00 I use the simple way . myeditor.Text = my massive striking; Thank you very much net 8 maui last version android 34
-
Anonymous
2023-12-04T08:12:43.36+00:00 Can you share a mini demo with us? I added a button and set 40000 characters in the click event by using
myeditor.Text = my massive striking;application do not freeze any more. -
Haviv Elbsz • 2,111 Reputation points
2023-12-04T09:35:26.5366667+00:00 Hi Lu and thank you very much. I want to clear the situation. when all the text moved there is no freeze and the UI is responsive. but the user needs to wait about a second or two so all the text are moved. Do I can put this statement in an async method. Thank you very much.
-
Anonymous
2023-12-04T09:45:46.1366667+00:00 the user needs to wait about a second or two so all the text are moved.
Do you want to add a delay, after moving all the text?
Do I can put this statement in an async method.
Can you share detailed information about statement or async method?
-
Deleted
This comment has been deleted due to a violation of our Code of Conduct. The comment was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
-
Deleted
This comment has been deleted due to a violation of our Code of Conduct. The comment was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
-
Haviv Elbsz • 2,111 Reputation points
2023-12-04T11:07:55.1533333+00:00 Hi Lu Do this async method can help private Task moveText() { return Task.Run(() => { OutputTB.Text = aqualityResults; }, ct); //return Task.Run } //private Task moveText And here is my real code. its only contains the move text because its hard to extract all related procedsure. Thank you for any help. ================================================================================================ private async void CheckEqualityCKB_CheckedChanged(object sender, CheckedChangedEventArgs e) { int j, tempNum = 0; int chunkN = 20000; string chunkStr = "", restStr = ""; if(String.IsNullOrEmpty(InputTB.Text)) { CheckEqualityCKB.IsChecked = false; return; } if(!Regex.IsMatch(SetsNosTB.Text, @"^\s*\d+\s+\d*\s*$")) { CheckEqualityCKB.IsChecked = false; return; } if(!Regex.IsMatch(ThisValueTB.Text, @"^\s*\d+\s*$")) { CheckEqualityCKB.IsChecked = false; return; } setsNos1 = 0; setsNos2 = 0; if(Regex.IsMatch(SetsNosTB.Text, @"^\s*\d+\s+\d*\s*$")) { MatchCollection matcheSetsNos = Regex.Matches(SetsNosTB.Text, @"\d+"); if(matcheSetsNos.Count > 1) { setsNos1 = Convert.ToInt32(matcheSetsNos[0].Value); setsNos2 = Convert.ToInt32(matcheSetsNos[1].Value); } else { setsNos1 = Convert.ToInt32(matcheSetsNos[0].Value); } } thisValue = 0; if(Regex.IsMatch(ThisValueTB.Text, @"^\s*\d+\s*$")) { string tmpstr = ThisValueTB.Text.Trim(); tempNum = Convert.ToInt32(tmpstr); thisValue = tempNum; } //-------------------------------------------------------------- start Relevent code if(CheckEqualityCKB.IsChecked) { if (!m_running) { m_running = true; m2_cancelTokenSource = new CancellationTokenSource(); try { RunButton.IsEnabled = false; baseXTB.IsEnabled = false; OpenPuzzles.IsEnabled = false; Expander_1.IsExpanded = false; OutputTB.Text = ""; await searchEqualsInSet1Set2(m2_cancelTokenSource.Token); CheckEqualityCKB.IsChecked = false; } catch (OperationCanceledException) { OutputTB.Text += "\nCanceled"; } finally { m_running = false; m2_cancelTokenSource = null; } } else { m2_cancelTokenSource.Cancel(); } OutputTB.Text = aqualityResults; // The problem is here await Task.Delay(100); var lastChild = scroll.Children.LastOrDefault(); if (lastChild != null) await scroll.ScrollToAsync(lastChild, ScrollToPosition.End, false); } //-------------------------------------------------------------- end Relevent code } //----------------------------------------------------------------------------- private Task searchEqualsInSet1Set2(CancellationToken ct) { return Task.Run(() => { int j, i, k, equalityCnt = 0; List<int> targetNi = new List<int>(); List<int> targetNj = new List<int>(); bool noEquality = false; targetNi.Clear(); targetNj.Clear(); equalityCnt = 0; if (posMatches[setsNos1].Count > 0 && posMatches[setsNos2].Count > 0) { for (i = 0; i < posMatches[setsNos1].Count; i++) { ct.ThrowIfCancellationRequested(); for (j = 0; j < posMatches[setsNos2].Count; j++) { if (posMatches[setsNos1][i] == posMatches[setsNos2][j]) { equalityCnt += 1; targetNi.Add(i); targetNj.Add(j); } } } } else { noEquality = true; } if (!noEquality) { MatchCollection set1Solutions = Regex.Matches(SearchInStr[1].Trim(), @"[-|\s\d]+"); MatchCollection set2Solutions = Regex.Matches(SearchInStr[2].Trim(), @"[-|\s\d]+"); MainThread.BeginInvokeOnMainThread(() => { OutputTB.Text += "\n Equality Occurrences Number = " + equalityCnt; }); aqualityResults = "\n Equality Results " + "\n"; for(k = 0; k < equalityCnt; k++) { aqualityResults += "--------------- " + (k+1) + " Matche = " + posMatches[setsNos1][targetNi[k]] + "\n"; aqualityResults += "\nSolution " + (targetNi[k]+1) + "\n" + set1Solutions[targetNi[k]].Value; aqualityResults += "\nSolution " + (targetNj[k]+1) + "\n" + set2Solutions[targetNj[k]].Value; } aqualityResults += "\n Equality Occurrences Number = " + equalityCnt; aqualityResults += "\n WAIT . . . " + "\n"; } else { MainThread.BeginInvokeOnMainThread(() => { OutputTB.Text += "\n\nNo Terms Sets Exist \n"; }); } }, ct); //return Task.Run } //private Task searchEqualsInSet1Set2 -
Anonymous
2023-12-05T08:30:11.41+00:00 Pease try to remove this line
await searchEqualsInSet1Set2(m2_cancelTokenSource.Token);in theCheckEqualityCKB_CheckedChanged, if application will not freeze, add this lineawait searchEqualsInSet1Set2(m2_cancelTokenSource.Token);Then open searchEqualsInSet1Set2 method, please remove following lines to exclude reason that UI thread is waiting for this result. If this application will not freeze, if so, please do not set the
OutputTB.Textin the Task, you can return this value and set it in theCheckEqualityCKB_CheckedChangedmethod.MainThread.BeginInvokeOnMainThread(() => { OutputTB.Text += "\n Equality Occurrences Number = " + equalityCnt; }); MainThread.BeginInvokeOnMainThread(() => { OutputTB.Text += "\n\nNo Terms Sets Exist \n"; });
Sign in to comment