Home > Net >  For help, questions about ListView load data is slow
For help, questions about ListView load data is slow

Time:11-13

Read a list of data is 2000, in the local test fast, about 2 seconds, but change the database connection to the network server, speed is slow, about 30 seconds, speed quickly, the program is copied to the server database connection with the network IP or. Are all the same shall not affect the speed, the server bandwidth 5 m, please god help
 
Private void reminderListUpload ()
{
Int num=0;
Int qtid=int. Parse (this. CbGroupQuestionType. SelectedValue. ToString ());
LitRge=rgeM. GetListArray_P (DateTime. Now. ToString (" yyyy - MM - dd "), 1, qtid);//database query need to load data
If (litRge. Count & gt; 0)
{
Enclosing lvReminderList. Items. The Clear ();
This. LvReminderList. BeginUpdate ();
Foreach (ReminderGrouping_ext_P rg litRge) in//traverse the query of data
{
Rg) reminderLogSum=rleS) CalcCount (" reminderId="+ rg. Id);
This. BackgroundWorker1. ReportProgress (num);
ListViewItem lv=new ListViewItem ();
Lv. UseItemStyleForSubItems=false;
Lv. Text=rg. Id. The ToString ();//set the first line shows the data
//bind the remaining columns of data
Lv. SubItems. Add ((num + 1). The ToString ());
Lv. SubItems. Add (rg) carNumber) Trim (), ToString ());
Lv. SubItems. Add (rg) custName) Trim ());
Lv. SubItems. Add (rg) custPhone1) Trim () + ", "+ rg. CustPhone1. The Trim ());

/* almost does not affect the following code loaded */
If (rg) isOffer==1)
{
Lv. SubItems. Add (" yes ", Color, Empty, Color, Green, null);
}
The else
{
Lv. SubItems. Add (" no ");
}
If (int. Parse (rg) reminderLogSum) ToString ()) & lt; 7 & amp; & Int. Parse (rg) reminderLogSum) ToString ()) & gt;
=3){
Lv. SubItems. Add (rg) reminderLogSum) ToString (), Color, Empty, Color, Yellow, null);
}
Else if (int. Parse (rg) reminderLogSum) ToString ()) & gt;=7)
{
Lv. SubItems. Add (rg) reminderLogSum) ToString (), Color, Empty, Color. Red, null);
}
The else
{
Lv. SubItems. Add (rg) reminderLogSum) ToString ());
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Lv. SubItems. Add (rg) questionTypeName) Trim ());
Lv. SubItems. Add (rg) reminderTime) ToString ());
Lv. SubItems. Add (rg. Few. ToString ());
Lv. SubItems. Add (rg) updateTime) ToString ());
Lv. SubItems. Add (rg) addTime) ToString ());
//after the row data to create added to the list
Enclosing lvReminderList. Items. The Add (lv);
Num++;
}
This. LvReminderList. EndUpdate ();
}
The else
{
Enclosing lvReminderList. Items. The Clear ();
}
}

CodePudding user response:

You give this code litRge=rgeM. GetListArray_P (DateTime. Now. The ToString (" yyyy - MM - dd "), 1, qtid);//database query need to load data
Before and after adding a logging time; See if the database connection problems, and is the first time loading is quite slow, 30 seconds have a little not normal,

CodePudding user response:

1, the query need to query field,
2. Data query to the ListView paging display at https://www.cnblogs.com/suntanyong88/p/5531482.html

CodePudding user response:

reference 1/f, mouse cried dead cat replies:
you give this code litRge=rgeM. GetListArray_P (DateTime. Now. The ToString (" yyyy - MM - dd "), 1, qtid);//database query need to load data
Before and after adding a logging time; See if the database connection problems, and is the first time loading is quite slow, abnormal 30 seconds,


 
A Stopwatch watch=new Stopwatch ();//instantiate a monitoring object
Watch. Start ();//start monitoring business logic
LitRge=rgeM. GetListArray_P (DateTime. Now. ToString (" yyyy - MM - dd "), 1, qtid);
Thread.sleep (10);//thread will delay 10 milliseconds, more than one such test, how to use to the thread in
Watch. Stop ();//end monitoring
MessageBox. Show (watch. ElapsedMilliseconds. ToString ());//output timing results, unit: ms

Connect to the remote server is 587 milliseconds, put on the server program is 56 milliseconds,

CodePudding user response:

Remote access to the database is inherently slow, and don't agree to connect to a remote database, had better add a WebService up in the middle, can consider to use WCF, WebService with data on a server or the same local area network (LAN),

CodePudding user response:

On the Internet, not recommended for frequent connection is established, then the network session, the establishment of a connection (TCP handshake), closed will consume a large amount of time, suggest to increase the connection pool, or a one-time gain, update the bulk data,
In the machine, the network connection go loopback (loop), much faster and without being limited by the bandwidth,

CodePudding user response:

This kind of situation I don't care about your code first, we use third party neutral test program to test,

If the third party neutral code as well as a result, then submit your test report for your leadership to think of some way to
If the third party neutral code no problem, then on to come over to ask how to solve the problem of your own code,

Ps: we come to a practical situation, a field programmer debugging according to document a serial port equipment, debugging, debugging 3 days and manufacturer own debugging tools can, each said each other there is a problem, we said ok, let alone who has a problem, use third party neutral tool testing, test results on both sides there is no problem, the problem is "document is wrong, the scene of the actual written agreement and document is not the same as"
  •  Tags:  
  • C#
  • Related