本文整理汇总了C#中System.IO.StreamReader.ReadLineAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader.ReadLineAsync方法的具体用法?C# System.IO.StreamReader.ReadLineAsync怎么用?C# System.IO.StreamReader.ReadLineAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了System.IO.StreamReader.ReadLineAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileLinesEnumeratorBlock
public static IPropagatorBlock<File, FileLine> GetFileLinesEnumeratorBlock()
{
var resultsBlock = new BufferBlock<FileLine>();
var actionBlock = new ActionBlock<File>(
async file =>
{
using (var reader = new System.IO.StreamReader(new System.IO.FileStream(
file.FullPath,
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.FileShare.Read,
bufferSize: 4096,
useAsync: true)))
{
string line;
var row = 1;
while ((line = await reader.ReadLineAsync()) != null)
{
if (!string.IsNullOrWhiteSpace(line))
{
resultsBlock.Post(new FileLine(file, row, line));
}
row++;
}
}
},
new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Utils.GlobalMaxDegreeOfParallelism });
actionBlock.PropagateCompleted(resultsBlock);
return DataflowBlock.Encapsulate(actionBlock, resultsBlock);
}
示例2: FindByNameAsync
// 根据用户名找用户
public async Task<IdentityUser> FindByNameAsync(string userName)
{
using (var stream = new System.IO.StreamReader(_filePath))
{
string line;
IdentityUser result = null;
while ((line = await stream.ReadLineAsync()) != null)
{
var user = IdentityUser.FromString(line);
if (user.UserName == userName)
{
result = user;
break;
}
}
return result;
}
}
示例3: LoadBMSFileAsync
private async void LoadBMSFileAsync(IProgress<string> progress)
{
await Task.Run(async () =>
{
System.Console.WriteLine("Load start.");
IsLoading = true;
System.IO.FileStream fs
= new System.IO.FileStream(Path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
System.IO.StreamReader sr
= new System.IO.StreamReader(fs);
string result = string.Empty;
string buffer = await sr.ReadLineAsync();
while (buffer != null)
{
//progress.Report(buffer);
System.Console.WriteLine(buffer);
buffer.Replace("\n", "").Replace("\r", "");
if (buffer != string.Empty)
InterpretCommand(buffer);
result += buffer + System.Environment.NewLine;
buffer = await sr.ReadLineAsync();
}
sr.Close();
/* set bmsData magnitude */
foreach(BmsData source in ListBmsDataCh2) //error may happen because list is not initialized
{
foreach (BmsData target in ListBmsData)
{
if (target.BarNumber == source.BarNumber)
{
target.BarMagnitude = source.BarMagnitude;
}
}
}
/* calc time */
int bar = 0;
int tempTime = 10000;
int nextTime = tempTime;
ListBmsData.Sort((a, b) => a.BarNumber - b.BarNumber);
foreach(BmsData tmp in ListBmsData)
{
if (bar == tmp.BarNumber)
{
tmp.calcObjectTime(tempTime);
}
else if(bar + 1 == tmp.BarNumber){
tempTime = nextTime;
nextTime = tmp.calcObjectTime(tempTime);
bar++;
}
}
/* check bms data */
foreach(BmsData tmp in ListBmsData)
{
if(tmp.Channel == 11)
tmp.printBmsData();
}
/* check wav data */
/*
foreach(KeyValuePair<int, Wav> dic in WavDictionary)
{
System.Console.WriteLine("Wav{0}:{1}, {2}", dic.Key, dic.Value.FileName, dic.Value.Number);
}
*/
IsLoading = false;
}
);
}
示例4: CargaPaisesAsync
/// <summary>
/// Carga las palabras y su definicion de forma asincrona y verifica que no haya ningun problema
/// </summary>
/// <returns>The words async.</returns>
async Task CargaPaisesAsync ()
{
//Obtiene el recursos desde la tarea asincrona para poder abrir un input stream
//y leer el archivo de recurso alojado en la carpeta raw
var resources = helperContext.Resources;
var inputStream = resources.OpenRawResource (Resource.Raw.paises);
using (var reader = new System.IO.StreamReader(inputStream)) {
try {
String line;
//ciclo que lee una linea del archivo
while ((line = await reader.ReadLineAsync ()) != null) {
//Hace un split de la linea usando como separador el carcter "@"
String[] strings = TextUtils.Split (line, "@");
//verifica que tenga dos elementos la linea(la palabra y su definicion)
if (strings.Length < 2)
continue;
//invoca al metodo para guardar la palabra y su definicion en la tabla
long id = AddPais(strings [0].Trim (), strings [1].Trim ());
if (id < 0)
{
Log.Error (TAG, "unable to add word: " + strings [0].Trim ());
}
}
} finally {
reader.Close ();
}
}
Log.Debug (TAG, "DONE loading words.");
}