Home > Net >  How to solve using c # WinForm project controls is large caton problem
How to solve using c # WinForm project controls is large caton problem

Time:09-22

How to solve using c # WinForm project controls more refresh problems  , specific as follows:

CodePudding user response:

If there is nothing wrong with program, the interface design is reasonable, the only consider a better performance (memory, memory is big) machines,

CodePudding user response:

Too many controls, if required must be loaded at a time, had better give a progress bar or message;
If there is no mandatory requirements, in accordance with the feature points in a class,
In the left navigation tree, put the different controls to different Tab,

CodePudding user response:

Has nothing to do with the UI processing should be separate, asynchronous execution, and then when the main thread is performed before call to update the interface, such as testing the following example:
 using System; 
Using System. The Threading;
using System.Windows.Forms;

The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}

Void the button1_Click (object sender, EventArgs e)
{
For the Text="beginning of the test";
The Test ();
}

Void Test ()
{
Thread.sleep (10000);
This. For. Text="test";
}
}
}

When you click on the button, you will find that the interface card died within 10 seconds, the window way root can't use the mouse to drag! This procedure is very bad, and change to the
 using System; 
Using System. The Threading;
Using System. The Threading. The Tasks;
using System.Windows.Forms;

The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}

Async void button1_Click (object sender, EventArgs e)
{
For the Text="beginning of the test";
Await the Test ();
This. For. Text="test";
}

Task Test ()
{
The return of Task. The Run (()=& gt;//has nothing to do with the UI refresh statement in this anonymous delegate to execute
{
Thread.sleep (10000);
});
}
}
}
you will find in the execution of a time-consuming process can also drag the window freely,

Suppose to be modified in the process of asynchronous concurrent window control, then you need to use the entrusted to access controls, for example:
 using System; 
Using System. The Threading;
Using System. The Threading. The Tasks;
using System.Windows.Forms;

The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}

Async void button1_Click (object sender, EventArgs e)
{
For the Text="beginning of the test";
Await the Test ();
This. For. Text="test";
}

Task Test ()
{
The return of Task. The Run (()=& gt;//has nothing to do with the UI refresh statement in this anonymous delegate to execute
{
Thread.sleep (2500);
This. For the BeginInvoke (delegate (Action)
{
This. For. Text="1";
});
Thread.sleep (2500);
This. For the BeginInvoke (delegate (Action)
{
This. For. Text="2";
});
Thread.sleep (2500);
This. For the BeginInvoke (delegate (Action)
{
This. For. Text="3";
});
Thread.sleep (2500);
});
}
}
}

Here, in the execution of a time consuming process of asynchronous visited UI interface controls, you need to use the BeginInvoke entrusted to operate the control, use the BeginInvoke. Entrusted to Invoke operation control, which is 15 years ago in the net of some operation specification,

CodePudding user response:

Simple summarize, is, in fact, most of the time you use has nothing to do with the UI interface operation give somebody else's UI thread to "card dead, blocked, causing interface look dead, actually interface can be very sensitive, can at any time to refresh, can quickly respond to various events, not application form can not, is the designer's knowledge, is to blame,

CodePudding user response:

Upstairs irrelevant answer, the somebody else is controls more display card, pay attention to the topic,

CodePudding user response:

Sp1234 has answered,
Key is to read data, UI binding these operations, asynchronous,

If some SQL need of optimization and so on, did not elaborate,
Outline is the main thread and asynchronous separation,

CodePudding user response:

reference 6 floor is anger god reply:
sp1234 has answered,
Key is to read data, UI binding these operations, asynchronous,

If some SQL need of optimization and so on, did not elaborate,
Outline is the main thread and asynchronous detach,

The somebody else say control, display card, don't say because reading the background data interface feign death, you are not the topic

CodePudding user response:

refer to 7th floor wangmoxhn response:
Quote: refer to the sixth floor is nu month god reply:
sp1234 has answered,
Key is to read data, UI binding these operations, asynchronous,

If some SQL need of optimization and so on, did not elaborate,
Outline is the main thread and asynchronous detach,

The somebody else say control, display card, don't say because reading the background data interface feign death, you are not the topic

I don't know you don't understand,,,
The main thread of the UI data binding is the main culprit, interface caton
So we say that rely on asynchronous to solve,

CodePudding user response:

refer to 7th floor wangmoxhn response:
Quote: refer to the sixth floor is nu month god reply:
sp1234 has answered,
Key is to read data, UI binding these operations, asynchronous,

If some SQL need of optimization and so on, did not elaborate,
Outline is the main thread and asynchronous detach,

The somebody else say control, display card, don't say because reading the background data interface feign death, you are not the topic


Each of the topic of focus, already have the difference,
How to conclude that you think is right, only confirmed, such as the building Lord knows,

CodePudding user response:

reference 3 floor interacting in a professional developer response:
has nothing to do with the UI processing should be separate, asynchronous execution, and then when the main thread is performed before call to update the interface, such as testing the following example:
 using System; 
Using System. The Threading;
using System.Windows.Forms;

The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}

Void the button1_Click (object sender, EventArgs e)
{
For the Text="beginning of the test";
The Test ();
}

Void Test ()
{
Thread.sleep (10000);
This. For. Text="test";
}
}
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related