maui user interface responsivity issue

Haviv Elbsz 2,071 Reputation points
2022-09-09T14:57:14.27+00:00

Hi all

I rewritten a winforms app to maui app
this app run a long processing method

In winforms the UI is responsive but
in maui isn't.

note this method while processing is writing
results text to a textbox in winforms
and to an editor in maui.

Note if uncommenting this statement
//if(results == 1) ==> If huge results processing for cancel test // I added this for testing only

then when there a huge processing the cancel is succeeded but if commented
cancel do not succeed.

Note that in small processing cancel always succeed when this statement commented

    public Task longthy_method(CancellationToken ct)  
    {  
  
      return Task.Run(() =>  
      {  
  
        try  
        {  
  
          . . . . .  
  
          progressBar.Progress = 0;  
  
     
          for(int combs = 0; combs < Total; combs++)  
          {  
  
       
            while (iPN < PN)  
            {  
  
                . . . .    
  
    
                while(iPY < PY)  
                {  
  
                  if (ct.IsCancellationRequested)  
                  {     
                    stopwatch.Stop();  
                    strOutputTBText += "Time elapsed:\r\n" + stopwatch.Elapsed;  
                    strOutputTBText += "\r\n";  
                    MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += strOutputTBText;});  
                    throw new OperationCanceledException(ct);  
                  }  
  
                  . . . . .  
            
                            //if(results == 1) ==> If huge results processing for cancel test  
                            MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += thisSolution + "\r\n";});  
  
                        }  
  
                      }  
  
                    }  
  
    
  
                }//*** while(iPY < PY)  
  
  
  
            }//*** while (iPN < PN)  
  
    
  
          }//for(combs  
  
  
  
  
        }  
        catch (Exception ex)  
        {  
          if(ex.ToString().Contains("OperationCanceledException"))  
          {  
            //  
          }  
          else  
          {  
            strOutputTBText = "\r\n\r\n";  
            strOutputTBText += $"Exception = " + ex + "\r\n";  
            strOutputTBText += $"Invalid Output";  
            strOutputTBText += "\r\n\r\n";  
            //if(results == 1) ==>   //If huge results processing for cancel test  I added this for testing only  
            MainThread.BeginInvokeOnMainThread(() => {OutputTB.Text += strOutputTBText;});  
          }  
        }  
        finally  
        {  
          progressBar.Progress = 0.0;  
        }  
  
  
      }, ct);  
  
  
    }//longthy_method  
  
  

can someone help in this

thank you very much

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,542 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 65,661 Reputation points
    2022-09-12T16:22:21.54+00:00

    you are queuing up control update requests on the UI thread. this is probably tying up the UI thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.