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


C# StreamWriter.WriteLineAsync方法代码示例

本文整理汇总了C#中System.IO.StreamWriter.WriteLineAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.WriteLineAsync方法的具体用法?C# StreamWriter.WriteLineAsync怎么用?C# StreamWriter.WriteLineAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamWriter的用法示例。


在下文中一共展示了StreamWriter.WriteLineAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadDaysFromDatabase

        // чтение данных из текстового файла
        private void ReadDaysFromDatabase()
        {
            try
            {
                using (var reader = new StreamReader(Environment.CurrentDirectory + DataFile))
                {
                    uint allBudget, costsCount;
                    UInt32.TryParse(reader.ReadLine(), out allBudget);
                    UInt32.TryParse(reader.ReadLine(), out costsCount);
                    _allBudget = allBudget;
                    for (var i = 0; i < costsCount; i++)
                    {
                        var costsString = reader.ReadLine();
                        var date = reader.ReadLine();

                        uint costs;
                        UInt32.TryParse(costsString, out costs);
                        _days.Add(new Day(DateTime.Parse(date), costs));
                    }
                }
            }
            catch (Exception)
            {
                // файл с данными не существует - создадим его
                using (var writer = new StreamWriter(Environment.CurrentDirectory + DataFile))
                {
                    // бюждет - незвестен
                    // кол-во трат - неизвестно
                    writer.WriteLineAsync("0");
                    writer.WriteLineAsync("0");
                }
            }
        }
开发者ID:GZNigmatzyanova,项目名称:KPFUExercises,代码行数:34,代码来源:MainWindow.xaml.cs

示例2: WriteToStreamAsync

 public override async Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
 {
     using (stream)
     {
         Encoding encoding = SelectCharacterEncoding(content.Headers);
         using (var writer = new StreamWriter(stream, encoding))
         {
             var individuals = value as IEnumerable<Individual>;
             if (individuals != null)
             {
                 foreach (var individu in individuals)
                 {
                     await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individu.Id, individu.FirstName, individu.LastName));
                 }
                 await writer.FlushAsync();
             }
             var individual = value as Individual;
             if (individual != null)
             {
                 await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individual.Id, individual.FirstName, individual.LastName));
                 await writer.FlushAsync();
             }
         }
     }
 }
开发者ID:Redenil,项目名称:RDAcademy,代码行数:25,代码来源:CsvTextMediaFormatter.cs

示例3: WorkAsync

        private static async Task WorkAsync(Channel channel)
        {
            using (channel)
            {
                using (var reader = new StreamReader(channel))
                {
                    using (var writer = new StreamWriter(channel))
                    {
                        string request = await reader.ReadLineAsync();
                        await writer.WriteLineAsync(request);
                        await writer.FlushAsync();

                        request = await reader.ReadLineAsync();
                        await writer.WriteLineAsync(request);
                        await writer.FlushAsync();

                        Console.WriteLine("Server waiting for close");

                        if (reader.EndOfStream)
                        {
                            Console.WriteLine("Server feel right!");
                        }

                        await channel.StopSendingAsync();
                        await channel.FlushAsync();
                    }
                }
            }
        }
开发者ID:cshung,项目名称:MultiplexingLab,代码行数:29,代码来源:Program.cs

示例4: ClientWork

        private async void ClientWork(object state)
        {
            int clientId = (int)state;
            using (var channel = this.connection.ConnectChannel())
            {
                using (StreamWriter writer = new StreamWriter(channel))
                {
                    using (StreamReader reader = new StreamReader(channel))
                    {
                        string request = string.Format("Hello from {0}", clientId);
                        string response;
                        await writer.WriteLineAsync(request);
                        await writer.FlushAsync();
                        response = await reader.ReadLineAsync();
                        await writer.WriteLineAsync(request);
                        await writer.FlushAsync();
                        response = await reader.ReadLineAsync();
                        await channel.StopSendingAsync();
                        await channel.FlushAsync();
                        if (reader.EndOfStream)
                        {
                            Console.WriteLine("Client feel right!");
                        }
                    }
                }
            }

            if (Interlocked.Decrement(ref pendingCount) == 0)
            {
                lock (termLock)
                {
                    Monitor.Pulse(termLock);
                }
            }
        }
开发者ID:cshung,项目名称:MultiplexingLab,代码行数:35,代码来源:Program.cs

示例5: ReadOutChannels

        public static async Task ReadOutChannels(XmlTvReader reader, StreamWriter resultsFileStream)
        {
            var channels = reader.GetChannels().Distinct().ToList();

            resultsFileStream.Write(EntityExtensions.GetHeader("Channels"));

            foreach (var channel in channels)
            {
                System.Console.WriteLine("Retrieved Channel: {0} - {1}", channel.Id, channel.DisplayName);
                resultsFileStream.Write(channel.GetChannelDetail());
            }

            var totalProgrammeCount = 0;

            resultsFileStream.Write("\r\n");
            foreach (var channel in channels)
            {
                System.Console.WriteLine("Processing Channel: {0}", channel.DisplayName);

                resultsFileStream.Write(EntityExtensions.GetHeader("Programs for " + channel.DisplayName));
                var channelProgrammeCount = await ReadOutChannelProgrammes(reader, channel, resultsFileStream);

                totalProgrammeCount += channelProgrammeCount;
                await resultsFileStream.WriteLineAsync(String.Format("Total Programmes for {1}: {0}", channelProgrammeCount, channel.DisplayName));
            }

            await resultsFileStream.WriteLineAsync(String.Format("Total Programmes: {0}", totalProgrammeCount));
        }
开发者ID:MediaBrowser,项目名称:Emby.XmlTv,代码行数:28,代码来源:Program.cs

示例6: Save

        public async Task Save(string path, BlackHoleGameTable gameTable)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(path))
                {
                    // save the game status and details
                    writer.Write(gameTable.TableSize + " ");
                    await writer.WriteAsync(gameTable.GameStatus + " ");
                    await writer.WriteAsync(gameTable.CoordinatesOfChosenField.Item1 + " " + gameTable.CoordinatesOfChosenField.Item2 + " ");
                    await writer.WriteAsync(gameTable.IsGameActive + " ");
                    await writer.WriteAsync(gameTable.PlayerAScore + " ");
                    await writer.WriteAsync(gameTable.PlayerBScore + "");

                    // save the game table values
                    await writer.WriteLineAsync();
                    for (Int32 row = 0; row < gameTable.TableSize; ++row)
                    {
                        for (Int32 column = 0; column < gameTable.TableSize; ++column)
                        {
                            await writer.WriteAsync(gameTable[row, column] + " ");
                        }
                        await writer.WriteLineAsync();
                    }
                }
            }
            catch
            {
                throw new BlackHoleGameDataException("Save file path is wrong.");
            }
        }
开发者ID:mozsik,项目名称:BlackHoleGame,代码行数:31,代码来源:BlackHoleGameFileDataAccess.cs

示例7: DoSomethingWithClientAsync

	    public async Task DoSomethingWithClientAsync()
	    {
		        try
		        {
			            using (var stream = _client.GetStream())
				            {
				                using (var sr = new StreamReader(stream))
				                using (var sw = new StreamWriter(stream))
					                {
					                    await sw.WriteLineAsync("Hi. This is x2 TCP/IP easy-to-use server").ConfigureAwait(false);
					                    await sw.FlushAsync().ConfigureAwait(false);
					                    var data = default(string);
					                    while (!((data = await sr.ReadLineAsync().ConfigureAwait(false)).Equals("exit", StringComparison.OrdinalIgnoreCase)))
		                    {
		                        await sw.WriteLineAsync(data).ConfigureAwait(false);
		                        await sw.FlushAsync().ConfigureAwait(false);
		                    }
		                }
		
		            }
		        }
		        finally
		        {
		            if (_ownsClient && _client != null)
		            {
		                (_client as IDisposable).Dispose();
		                _client = null;
		            }
		        }
		}
开发者ID:littlewingsoft,项目名称:gambleServer,代码行数:30,代码来源:ClientWorking.cs

示例8: WriteTo

        public static async Task WriteTo(IHttpHeaders headers, Stream stream)
        {
#if PCL && !ASYNC_PCL
            var writer = new StreamWriter(new NonDisposableStream(stream), Encoding.UTF8, 128);
#else
            var writer = new StreamWriter(stream, Encoding.UTF8, 128, true);
#endif
            try
            {
                writer.NewLine = "\r\n";

                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        await
                            writer.WriteLineAsync($"{header.Key}: {string.Join(", ", header.Value)}");
                    }
                }

                await writer.WriteLineAsync();
            }
            finally
            {
                writer.Dispose();
            }
        }
开发者ID:evnik,项目名称:restsharp.portable,代码行数:27,代码来源:HttpHeaderContent.cs

示例9: ProcessQueue

        private async Task ProcessQueue(string queue)
        {
            try
            {
                var events = MessageQueue.GetBatch<PerfEvent>(queue)
                    .ToList();

                // Group by hour
                var groups = events.GroupBy(e => new { e.TimestampUtc.Date, e.TimestampUtc.Hour });

                await Task.WhenAll(groups.Select(async group =>
                {
                    if (group.Any())
                    {
                        string dir = Path.Combine(LogDirectory, queue);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        // Determine the file name for the log
                        string fileName = Path.Combine(
                            dir,
                            String.Format("{0:yyyyMMdd}{1}.csv", group.Key.Date, group.Key.Hour));

                        // Append to the log
                        using (var strm = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None))
                        using (var writer = new StreamWriter(strm))
                        {
                            foreach (var evt in group)
                            {
                                var fields = evt.Fields.OrderBy(p => p.Key);
                                if (strm.Length == 0)
                                {
                                    await writer.WriteLineAsync(
                                        "Source,Timestamp,Duration," + String.Join(",", fields.Select(f => f.Key)));
                                    await writer.FlushAsync();
                                }
                                await writer.WriteLineAsync(
                                    CsvEscape(evt.Source) + "," +
                                    CsvEscape(evt.TimestampUtc.ToString("O")) + "," + 
                                    CsvEscape(evt.Duration.TotalMilliseconds.ToString("0.00")) + "," + 
                                    String.Join(",", fields.Select(f => CsvEscape(f.Value == null ? String.Empty : f.Value.ToString()))));
                            }
                        }
                    }
                }));
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:hugoparedes,项目名称:NuGetGallery,代码行数:53,代码来源:ProcessPerfEvents.cs

示例10: LogUnhandledException

 public static async void LogUnhandledException(Exception e)
 {
     var logsFolder = await ApplicationData.Current.LocalFolder
         .CreateFolderAsync("Logs", CreationCollisionOption.OpenIfExists);
     var file = await logsFolder.CreateFileAsync(String.Format("{0}.log", DateTime.Now.Ticks));
     var stream = await file.OpenStreamForWriteAsync();
     using (var writer = new StreamWriter(stream))
     {
         await writer.WriteLineAsync(e.Message);
         if (e.StackTrace != null)
             await writer.WriteLineAsync(e.StackTrace);
     }
 }
开发者ID:michaellperry,项目名称:MyCon,代码行数:13,代码来源:App.xaml.cs

示例11: Listen

        protected async Task Listen(Socket socket) {
            Stream ioStream = socket.GetStream();
            StreamReader reader = new StreamReader(ioStream);
            StreamWriter writer = new StreamWriter(ioStream);

            await writer.WriteLineAsync(FtpResponse.PositiveCompletionReply.ServiceReady.ToString());
            await writer.FlushAsync();
            string command;
            while (true) {
                string result = await RunCommand(await reader.ReadLineAsync());
                await writer.WriteLineAsync(result);
                await writer.FlushAsync();
            }
        }
开发者ID:XuPeiYao,项目名称:IronFtpService,代码行数:14,代码来源:FtpSocket.cs

示例12: Invoke

 public async Task Invoke(IDictionary<string, object> environment)
 {
     var response = environment["owin.ResponseBody"] as Stream;
     using (var writer = new StreamWriter(response))
     {
         await writer.WriteLineAsync(string.Format("Demo Component!", _options.Name));
         foreach (var option in _options.MoreOptions)
         {
             _next.Invoke(environment);
             Console.WriteLine("I hope this works");
             await writer.WriteLineAsync(string.Format("Option: {0}", option));                    
         }
     }
 }
开发者ID:jeremyabbott,项目名称:SDNUG_Owin_Katana,代码行数:14,代码来源:DemoMiddlewareComponent.cs

示例13: LogError

 public static void LogError(string error)
 {
     string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     if (appPath != null)
     {
         string configFile = Path.Combine(appPath, "errorlogs.txt");
         var file = new StreamWriter(configFile, true);
         file.WriteLineAsync("-----------------");
         file.WriteLine(error);
         file.WriteLineAsync("---------------------");
         file.Close();
         Console.WriteLine("Error=>{0}", error);
     }
 }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:14,代码来源:FileUtility.cs

示例14: Invoke

 public async Task Invoke(IDictionary<string, object> environment)
 {
     var response = environment["owin.ResponseBody"] as Stream;
     if (response != null)
         using (var writer = new StreamWriter(response))
         {
             await writer.WriteLineAsync(string.Format("Hello {0}!", _options.Name));
             foreach (var option in _options.MoreOptions)
             {
                 //_next.Invoke(environment);
                
                 await writer.WriteLineAsync(string.Format("Option: {0}", option));
             }
         }
 }
开发者ID:jeremyabbott,项目名称:SDNUG_Owin_Katana,代码行数:15,代码来源:SdnugMiddlewareComponent.cs

示例15: SaveTokens_FileOk

        private async void SaveTokens_FileOk(object sender, CancelEventArgs e)
        {
            var cardsList = await Task.Run(() => { return this.tokenizationService.GetEntries().OrderBy(x => x.Token); });
            var filename = (sender as SaveFileDialog).FileName;
            using (StreamWriter sw = new StreamWriter(filename))
            {
                await sw.WriteLineAsync(string.Format("{0,-16} - {1,-16}", "Token", "Card number"));
                foreach (var item in cardsList)
                {
                    await sw.WriteLineAsync(string.Format("{0} - {1}", item.Token, item.CardNumber));
                }
            }

            UnlockScreen();
        }
开发者ID:ivailok,项目名称:BankCardsTokenization,代码行数:15,代码来源:ExportPage.xaml.cs


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