Home > Net >  Questions about the read TXT text content
Questions about the read TXT text content

Time:11-14

String [] lines=File. ReadAllLines (" D:/map. TXT ", Encoding, UTF8);//get TXT all content
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 IAsyncEnumerable AsyncStreamReadlines (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:

refer to the second floor weixin_43669653 response:
on baidu, I read online others say take flow is not slow, do not know whether useful!


Is not the problem of low slow or not. For instance I this debug log 1 g, if the overall disposable natural you have read into memory,

To stream line read, you can read while parsing show

As far as I'm with a new IAsyncEnumerable , just tell you that Microsoft has asynchronous iterators, let alone blog garden all day remember + string, the string over the blog garden does not tell you, you cried out, "the net to finish,.net is 49 nations" -- -- -- -- -- - we just said to say nations, also can only say that the blog garden that wave with string, is following blog garden to learn what all don't remember, just remember the string

CodePudding user response:

Use file streams, read a line with a line (low ° u ° ")? Tens of thousands of lines should be soon,
  •  Tags:  
  • C#
  • Related