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


C# TextWriter.Dispose方法代码示例

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


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

示例1: TextNullTextWriter

        public static void TextNullTextWriter(TextWriter output)
        {
            output.Flush();
            output.Dispose();

            output.WriteLine(decimal.MinValue);
            output.WriteLine(Math.PI);
            output.WriteLine();
            output.Flush();
            output.Dispose();
        }
开发者ID:neris,项目名称:corefx,代码行数:11,代码来源:Stream.NullTests.cs

示例2: CopyToAsync

 public static Task CopyToAsync(this TextReader reader, TextWriter writer, bool leaveReaderOpen, bool leaveWriterOpen)
 {
     return reader.PipeAsync(
         async () =>
         {
             var buffer = new char[Constants.CharBufferSize];
             int charsRead;
             while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0)
             {
                 await writer.WriteAsync(buffer, 0, charsRead).ConfigureAwait(false);
             }
         },
         leaveOpen: leaveReaderOpen,
         extraDisposeAction: leaveWriterOpen ? default(Action) : () => writer.Dispose()
     );
 }
开发者ID:rivy,项目名称:MedallionShell,代码行数:16,代码来源:PipeHelpers.cs

示例3: Add

        public static void Add(string msg, params object[] args)
        {
            if (!IsOn || s_IOErrorOccurred) return;

            try
            {
                if (args == null)
                {
                    s_writer.WriteLine(msg);
                }
                else
                {
                    s_writer.WriteLine(msg, args);
                }
                s_writer.Flush();
            }
            catch (IOException)
            {
                s_IOErrorOccurred = true;
                try
                {
                    s_writer.Close();
                    s_writer.Dispose();
                    s_writer = null;
                }
                catch
                {
                    // supress exceptions that occur during cleanup.
                }
                return;
            }
            catch (System.ObjectDisposedException)
            {
                s_IOErrorOccurred = true;
                try
                {
                    s_writer.Close();
                    s_writer.Dispose();
                    s_writer = null;
                }
                catch
                {
                    // supress exceptions that occur during cleanup.
                }
                return;
            }
        }
开发者ID:knowledgehacker,项目名称:Dryad,代码行数:47,代码来源:DryadLinqLog.cs

示例4: GenerateInsertStatement

 public void GenerateInsertStatement(string tableName, string whereClause,string outputFileName)
 {
     try
     {
         Initialize();
         _outPutFile = new StreamWriter(outputFileName);
         string columnList = GetColumnList(tableName).ToString();
         DataTable dTable = FormAndRunQuery(tableName, columnList, whereClause);
         FormInserts(dTable, tableName, columnList);
         _outPutFile.Close();
         _outPutFile = null;
     }
     catch (Exception e)
     {
         if(_outPutFile != null)
             _outPutFile.Dispose();
         throw e;
     }
 }
开发者ID:SarathR,项目名称:MS-Sql-Server-Script-generator,代码行数:19,代码来源:ScriptGenerator.cs

示例5: RemoveWriter

        /// <summary>
        /// Removes a writer from the log.
        /// </summary>
        public static void RemoveWriter(TextWriter writer, Boolean close)
        {
            if (close)
                writer.Dispose();

            InstallerLog._writers.Remove(writer);
        }
开发者ID:Pjanssen,项目名称:ScriptCenter,代码行数:10,代码来源:InstallerLog.cs

示例6: Serialize

 private XmlDocument Serialize(object obj)
 {
     StringWriter writer = null;
     try
     {
         writer = new StringWriter(CultureInfo.InvariantCulture);
         XmlSerializer serializer = new XmlSerializer(obj.GetType());
         serializer.Serialize(writer, obj);
         XmlDocument xDoc = new XmlDocument();
         xDoc.LoadXml(writer.ToString());
         return xDoc;
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         if (writer != null)
         {
             writer.Close();
             writer.Dispose();
         }
     }
 }
开发者ID:jordivila,项目名称:Net_MVC_NLayer_Generator,代码行数:25,代码来源:Common.cs

示例7: GenerateOutput

        public void GenerateOutput()
        {
            Console.WriteLine("* Generating code into '" + m_outputFilename + "'");

            var directory = Path.GetDirectoryName(m_outputFilename);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            using (var stream = new FileStream(m_outputFilename, FileMode.Create, FileAccess.Write))
            {
                m_outputFile = new StreamWriter(stream);
                EmitPrelude();
                EmitPublic();
                EmitPrivate();
                m_outputFile.Dispose();
            }
        }
开发者ID:rabbitmq,项目名称:rabbitmq-dotnet-client,代码行数:20,代码来源:Apigen.cs

示例8: Dispose

 public static void Dispose(TextWriter w)
 {
     if (!__DEBUG__) return;
     w.Flush();
     w.Close();
     w.Dispose();
 }
开发者ID:chrisbaldwinj,项目名称:Crawler,代码行数:7,代码来源:Crawler.cs

示例9: RestoreConsoleOut

    static string RestoreConsoleOut(TextWriter defaultWriter, TextWriter capture)
    {
      if (defaultWriter == null)
      {
        throw new ArgumentNullException("defaultWriter");
      }

      if (capture == null)
      {
        throw new ArgumentNullException("capture");
      }

      Console.SetOut(defaultWriter);

      try
      {
        capture.Flush();

        return capture.ToString();
      }
      finally
      {
        capture.Dispose();
      }
    }
开发者ID:benlovell,项目名称:machine.specifications,代码行数:25,代码来源:ConsoleRedirection.cs

示例10: addPick


//.........这里部分代码省略.........
                Console.Write("\nJesteś pewien że chcesz dodać ten zakład? Wpisz 'T' jeżeli tak, inny znak aby wyjść");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("\n-> ");
                s = Console.ReadLine();
                bool moznaWykonac = true;

                if (s.ToUpper() == "T")
                {

                    //
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SPRAWDŹ CZY RODZAJ ZAKŁADÓW ZGADZA SIĘ Z TWOIMI PREFERENCJAMI
                    //

                    try
                    {
                        textReader = new StreamReader(fileName);
                    }
                    catch (Exception e)
                    {

                    }
                    finally
                    {
                        s = textReader.ReadLine();
                        textArray = s.Split(znakiOdstepu);
                        string preferencja = textArray[10].ToUpper();
                        if (typZdarzenia != preferencja.ToUpper())
                        {
                            Console.ForegroundColor = ConsoleColor.DarkRed;
                            Console.Write("\nNie możesz grać zakładów tego rodzaju!");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            moznaWykonac = false;
                        }
                        textReader.Dispose();
                        textReader.Close();
                    }

                    //

                    int losingStreak = 0;

                    if (pickCount == 0)
                    {

                        bankrollTo = bankroll * (1 + expectedMonthlyIncome);
                        endDate = (today).AddMonths(1);

                        if (endDate.Year == today.Year)
                        {
                            howManyDaysLeft = endDate.DayOfYear - DateTime.Now.DayOfYear;
                            ileDoZarobkuDziennie = (bankrollTo - bankroll) / howManyDaysLeft;
                            startingAvarageIncome = ileDoZarobkuDziennie;
                        }
                        else
                        {
                            howManyDaysLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear;
                            ileDoZarobkuDziennie = (bankrollTo - bankroll) / howManyDaysLeft;
                            startingAvarageIncome = ileDoZarobkuDziennie;
                        }

                        if (probability == 0.0D)
                        {
                            probability = 1 / odd;
                        }

                        value = odd * probability;
开发者ID:mhoroszko,项目名称:Betting,代码行数:67,代码来源:Stake.cs

示例11: Stake

        public Stake()
        {
            try
            {
                textReader = new StreamReader(fileName);

            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            finally
            {

                string ileLinijekString = textReader.ReadLine();

                if (ileLinijekString != null)
                {
                    ileLinijek++;
                }

                textReader.Dispose();
                textReader.Close();

            }

            if (ileLinijek == 0)
            {
                try
                {
                    textWriter = new StreamWriter(fileName);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                finally
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("To twój pierwszy raz z programem BetProvider, podaj kilka danych\n");
                    Console.ForegroundColor = ConsoleColor.Gray;
                    nickname = "";
                    bankroll = 0.0D;
                    expectedMonthlyIncome = -0.1D;
                    avarageOdd = 1.65D;

                    Console.Write("Podaj swoje imię ( Format - znaki ) : ");
                    s = Console.ReadLine();
                    nickname = s;
                    while (nickname == "")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Nie podałeś swojego imienia, wprowadź ciąg znaków ( np. Wojtek ) : ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        nickname = Console.ReadLine();
                    }

                    int probowal = 0;
                    BANKROLL :

                    if (probowal == 0)
                    {
                        Console.Write("Podaj swój Bankroll ( Format - 00.00 ) : ");
                        probowal++;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("Nieprawidłowy format, bankroll może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }

                    s = Console.ReadLine();

                    try
                    {
                        bankroll = stringToDouble(s);
                    }
                    catch (Exception e)
                    {

                        while( true == true )
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("Nieprawidłowy format, bankroll może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            s = Console.ReadLine();

                            try
                            {
                                bankroll = stringToDouble(s);
                                break;
                            }
                            catch (Exception ee)
                            {

                            }
                            finally
                            {
                            }
//.........这里部分代码省略.........
开发者ID:mhoroszko,项目名称:Betting,代码行数:101,代码来源:Stake.cs

示例12: updatePick

        private void updatePick()
        {
            try
            {
                textReader = new StreamReader(fileName);
            }
            catch (Exception e)
            {

            }
            finally
            {
                ileLinijek = 0;

                s = textReader.ReadLine();

                while (s != null)
                {
                    ileLinijek++;
                    s = textReader.ReadLine();
                }
            }
            textReader.Dispose();
            textReader.Close();

            int updateChoice = 0;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("1");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write(". Aktualizuj zakład w grze");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\n2");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write(". Usuń dodany zakład");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\n3");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write(". Wróc do MENU");

            Console.Write("\n-> ");
            s = Console.ReadLine();

            while (updateChoice != 1 && updateChoice != 2 && updateChoice != 3)
            {
                try
                {
                    updateChoice = int.Parse(s);
                    break;
                }
                catch (Exception e)
                {
                    Console.Write("-> ");
                    s = Console.ReadLine();
                }
                finally
                { }

            }

            Console.Clear();

            switch (updateChoice)
            {
                case 1:

                    int i = 1;
                    string meczDoZmiany = "";
                    string infoDoZmiany = "";

                    try
                    {
                        textReader = new StreamReader(fileName);
                    }
                    catch (Exception e)
                    {

                    }
                    finally
                    {
                        i = 1;
                        textArray = null;
                        textArray = new string[ileLinijek];

                        while (i <= ileLinijek)
                        {
                            textArray[i-1] = textReader.ReadLine();
                            i++;
                        }

                        meczDoZmiany = textArray[i - 2];
                        infoDoZmiany = textArray[0];
                        textReader.Dispose();
                        textReader.Close();

                    }

                    // Update tego co trzeba

                    string[] meczDoZmianyDane = new string[11];
                    string[] infoDoZmianyDane = new string[11];
//.........这里部分代码省略.........
开发者ID:mhoroszko,项目名称:Betting,代码行数:101,代码来源:Stake.cs

示例13: transactions


//.........这里部分代码省略.........

                                }
                                finally
                                {
                                }
                            }

                        }
                        finally
                        {

                        }

                        if (doWplaty < 0)
                        {
                            goto DEPOSIT;
                        }

                        // Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome

                        // Wczytaj pierwszą linię
                        string pierwszaLinijka = "";
                        string reszta = "";

                        try
                        {
                            textReader = new StreamReader(fileName);
                        }
                        catch (Exception e) { }
                        finally
                        {
                            pierwszaLinijka = textReader.ReadLine();
                            reszta = textReader.ReadToEnd();
                            textReader.Dispose();
                            textReader.Close();
                        }
                        // Wczytać resztę komendą readToEnd
                        // Zmienić br ,ed ,brT, sai

                        bankroll += doWplaty;
                        bankrollTo = bankroll * (1 + expectedMonthlyIncome);
                        endDate = DateTime.Today.AddMonths(1);
                        int howManyDaLeft;
                        if (endDate.Year == DateTime.Now.Year)
                        {
                            howManyDaLeft = endDate.DayOfYear - DateTime.Now.DayOfYear;
                            startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft;

                        }
                        else
                        {
                            howManyDaLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear;
                            startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft;

                        }

                        // Zmienić pierwszą linię
                        // Zapisać all

                        try
                        {
                            textWriter = new StreamWriter(fileName);
                        }
                        catch (Exception e) { }
                        finally
                        {
开发者ID:mhoroszko,项目名称:Betting,代码行数:67,代码来源:Stake.cs

示例14: settings


//.........这里部分代码省略.........

                            }
                            finally
                            {
                            }
                        }

                    }
                    finally
                    {

                    }

                    if (uexpectedMonthlyIncome <= 0 || uexpectedMonthlyIncome > 1)
                    {
                        goto UEXPECTEDMONTHLYINCOME;
                    }

                        // Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome

                        // Wczytaj pierwszą linię
                        string pierwszaLinijka = "";
                        string reszta = "";

                        try
                        {
                            textReader = new StreamReader(fileName);
                        }
                        catch (Exception e) { }
                        finally
                        {
                            pierwszaLinijka = textReader.ReadLine();
                            reszta = textReader.ReadToEnd();
                            textReader.Dispose();
                            textReader.Close();
                        }

                        expectedMonthlyIncome = uexpectedMonthlyIncome;

                        // Wpisz

                        try
                        {
                            textWriter = new StreamWriter(fileName);
                        }
                        catch (Exception e) { }
                        finally
                        {
                            s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper();

                            textWriter.WriteLine(s);
                            textWriter.Write(reszta);
                            textWriter.Flush();
                            textWriter.Dispose();
                            textWriter.Close();
                        }
                        // ATTENTION

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("\n!! Ta zmiana będzie miała wpływ dopiero po zakończeniu danego cyklu !!");

                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.Write("\n\nNaciśniej ENTER aby wyjść...");

                        if (Console.ReadLine() != "EXIT")
                        {
开发者ID:mhoroszko,项目名称:Betting,代码行数:67,代码来源:Stake.cs

示例15: ParseCommandLineArgs

        static void ParseCommandLineArgs(string[] args)
        {
            file_path = Directory.GetCurrentDirectory() + "\\" + args[0];
            //Set the print value
            if (args.Contains("-verbose") == true)
            {
                print_level = 2;
            }
            else if (args.Contains("-print") == true)
            {
                print_level = 1;
            }
            else if (args.Contains("-silent") == true)
            {
                print_level = 0;
            }
            else
            {
                print_level = 1;// Default value of print
            }

            if(args.Contains("-step") == true)
            {
                step_mode = true;
            }

            if (args.Contains("-log") == true)
            {
                string logsFolder = Directory.GetCurrentDirectory() + "\\logs";
                StringBuilder sb = new StringBuilder(9);
                sb.Append(logsFolder);
                sb.Append("\\");
                sb.Append(Path.GetFileNameWithoutExtension(file_path));
                sb.Append("_");
                sb.Append(DateTime.Now.Year.ToString());
                sb.Append("_");
                sb.Append(DateTime.Now.Month.ToString().PadLeft(2, '0'));
                sb.Append("_");
                sb.Append(DateTime.Now.Day.ToString().PadLeft(2, '0'));
                sb.Append("_");
                sb.Append(DateTime.Now.Hour.ToString().PadLeft(2, '0'));
                sb.Append("_");
                sb.Append(DateTime.Now.Minute.ToString().PadLeft(2, '0'));
                sb.Append("_");
                sb.Append(DateTime.Now.Second.ToString().PadLeft(2, '0'));
                sb.Append(".txt");

                try
                {
                    if (Directory.Exists(logsFolder) == false)
                    {
                        try
                        {
                            Directory.CreateDirectory(logsFolder);
                        }
                        catch (Exception e)
                        {
                            if (print_level > 0)
                            {
                                Console.WriteLine("Logs directory could not be created: " + e.Message);
                            }
                            return;
                        }
                    }
                    logger = new StreamWriter(sb.ToString());
                }
                catch (Exception)
                {
                    logger.Close();
                    logger.Dispose();
                    if (print_level > 0)
                    {
                        Console.WriteLine("Log at {0} could not created", sb.ToString());

                        if (use_prompts == true)
                        {
                            Console.WriteLine("Exit? Y/N");
                            char key = Console.ReadKey().KeyChar;
                            if (key == 'y' || key == 'Y')
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
开发者ID:tngreene,项目名称:ConsideredHarmful,代码行数:87,代码来源:Program.cs


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