本文整理汇总了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();
}
示例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()
);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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();
}
}
}
示例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();
}
}
示例8: Dispose
public static void Dispose(TextWriter w)
{
if (!__DEBUG__) return;
w.Flush();
w.Close();
w.Dispose();
}
示例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();
}
}
示例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;
示例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
{
}
//.........这里部分代码省略.........
示例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];
//.........这里部分代码省略.........
示例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
{
示例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")
{
示例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;
}
}
}
}
}
}