当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.StreamReader.ReadLineAsync方法代码示例

本文整理汇总了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);
        }
开发者ID:eugene-sea,项目名称:FileWordsDataflow,代码行数:32,代码来源:FileLinesEnumerator.cs

示例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;
     }
 }
开发者ID:caicaishen,项目名称:netTest,代码行数:19,代码来源:UserStore.cs

示例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;
     }
     );
 }
开发者ID:ktcsi,项目名称:bmsPrototype,代码行数:68,代码来源:Tune.cs

示例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.");
			}
开发者ID:DiLRandI,项目名称:Xamarin.android,代码行数:38,代码来源:Manejador_db.cs


注:本文中的System.IO.StreamReader.ReadLineAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。