Invalid Winforms UI Request

I have a user interface and inside it.

While executed BackgroundWorker, it updates the user interface through Marshalling. The user interface did not respond during one of the runs. I pressed the pause button in Visual Studio to find out what was going on.

The following lines were shown in the Threads window:

  • Application.Run(new uxRunSetup());

  • private delegate void DisplayCounterHandler(int[] counts, int total);

    private void DisplayCounter(int[] counts, int total)    
     {  
        if (InvokeRequired)      
       {    
          //stuck on Invoke below.     
          Invoke(new DisplayCounterHandler(DisplayCounter), counts, total);     
                        return;  
       }  
       //some UI updates here.  
    }  
    

I read through this thread. My question is: let's say a call was called DisplayCounterHandler. However, BackgroundWorker is already complete. Could this lead to the user interface not responding and crashing?

Thank.

+3
source share
1 answer

You should switch your Invoke to BeginInvoke, i.e.

if(this.InvokeRequired)
{
  this.BeginInvoke(...);
  return;
}

// UI updates here

invoke , , - , , :

  • , (- )
  • -
  • , ,

- BeginInvoke, "" , .

-

+3

Source: https://habr.com/ru/post/1795126/


All Articles