for (int i=0; I & lt; Lines. Length; I++)//the length of the for loop TXT
{
String [] b=lines [I] the Split (' ');//string
ListView3. Items. The Add (new ListViewItem (new string [] {b [1]. The ToString (), b [0]. ToString ()}));
}
Now I write so
Then the TXT there are many
Hunan changsha
Guangdong shantou
Hubei xiaogan
Hunan changsha
Guangdong shantou
Hubei xiaogan
Hunan changsha
Guangdong shantou
Hubei xiaogan
Hunan changsha
Guangdong shantou
Hubei xiaogan
Hunan changsha
Guangdong shantou
Hubei xiaogan
But I found a problem is when I open the software will be a delay caton phenomenon but TXT if only a few lines of all the data from normal,
Excuse me bosses how to optimize! Or add a time delay? How many lines for example shows every 1 seconds
CodePudding user response:
String [] lines=await File. AppendAllLinesAsync ();This is solve your UI caton, but does not solve you read slowly,
Read slowly to solve, you can only read in a batch of a batch of stream
CodePudding user response:
On baidu, I read online others say take flow is not slow, do not know whether useful!CodePudding user response:
public async IAsyncEnumerableAsyncStreamReadlines (the FileInfo the FileInfo)
{
Using var fs=the fileInfo. OpenRead ();
Using var sr=new StreamReader (fs);
While (true)
{
The string line=await the sr. ReadLineAsync ();
If (line==null)
{
Yield break; break;
}
Yield return line.
}
}
The
await foreach (var line in AsyncStreamReadlines (new to the FileInfo (@ "F: \ debug log")))
{
Trace. WriteLine (line);
Await Task. Delay (100);//here I sleep a little bit about the, lest the UI refresh the main process caused by busy
}
CodePudding user response: