本文整理汇总了C#中System.IO.StreamWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.Flush方法的具体用法?C# System.IO.StreamWriter.Flush怎么用?C# System.IO.StreamWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了System.IO.StreamWriter.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryPrint
public void TryPrint(string zplCommands)
{
try
{
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect(this.m_IPAddress, this.m_Port);
// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(zplCommands);
writer.Flush();
// Close Connection
writer.Close();
client.Close();
}
catch (Exception ex)
{
this.m_ErrorCount += 1;
if(this.m_ErrorCount < 10)
{
System.Threading.Thread.Sleep(5000);
this.TryPrint(zplCommands);
}
else
{
throw ex;
}
}
}
示例2: FlowStatics
public static void FlowStatics()
{
System.IO.StreamWriter sw = new System.IO.StreamWriter("log.txt", false);
DataClasses1DataContext mydb = new DataClasses1DataContext(common.connString);
var message = mydb.LA_update1.Select(e => e.ip_version_MsgType).Distinct();
Dictionary<string, int> myDic = new Dictionary<string, int>();
foreach (string m in message)
{
myDic.Add(m, 0);
Console.Write(m + "--------------------");
Console.WriteLine(0);
sw.Write(m + "--------------------");
sw.WriteLine(0);
}
sw.Flush();
List<string> startmessage = new List<string>();
startmessage.Add("DTAP MM.Location Updating Request");
startmessage.Add("DTAP MM.CM Service Request");
startmessage.Add("DTAP RR.Paging Response");
startmessage.Add("BSSMAP.Handover Request");
foreach (var start in startmessage)
{
Dictionary<string, int> newDic = new Dictionary<string, int>();
foreach (KeyValuePair<string, int> pair in myDic)
newDic.Add(pair.Key, 0);
var a = from p in mydb.LA_update1
where p.ip_version_MsgType == start
select p.opcdpcsccp;
foreach (var b in a)
{
foreach (KeyValuePair<string, int> kvp in myDic)
{
var c = mydb.LA_update1.Where(e => e.opcdpcsccp == b).Where(e => e.ip_version_MsgType == kvp.Key).FirstOrDefault();
if (c != null)
newDic[kvp.Key] = newDic[kvp.Key] + 1;
}
}
foreach (var m in newDic.OrderByDescending(e => e.Value))
{
Console.Write(m.Key+"--------------------");
Console.WriteLine(m.Value);
sw.Write(m.Key + "--------------------");
sw.WriteLine(m.Value);
}
sw.Flush();
}
sw.Close();
}
示例3: init
private void init()
{
logTimer.Elapsed += new System.Timers.ElapsedEventHandler((object sender, System.Timers.ElapsedEventArgs e) =>
{
try
{
fs = new System.IO.FileStream(LogFile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
sw = new System.IO.StreamWriter(fs);
sw.BaseStream.Seek(0, System.IO.SeekOrigin.End);
lock(buffer)
{
foreach(String str in buffer)
{
sw.Write("[" + DateTime.Now.ToString() + "] ");
//sw.Flush();
sw.WriteLine(str);
sw.Flush();
}
buffer.Clear();
}
sw.Close();
fs.Close();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
});
logTimer.AutoReset = true; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
logTimer.Enabled = true; //是否触发Elapsed事件
logTimer.Start();
}
示例4: MainWindow
public MainWindow()
{
log_file = new System.IO.FileStream("log3.txt", System.IO.FileMode.Append);
log_sw = new System.IO.StreamWriter(log_file);
InitializeComponent();
ac_m = new ArchiveControl();
Console.SetOut(log_sw);
_LogTimer.Interval = System.TimeSpan.FromSeconds(5);
_LogTimer.Tick += flushLog;
_LogTimer.Start();
Console.WriteLine("========================================");
Console.WriteLine("MainWindow()");
Console.WriteLine(DateTime.Now.ToString());
log_sw.Flush();
write.mainWindow = this;
try
{
button_NP_Click(null, null);
button_NS_Click(null, null);
} catch { }
TabItem1.Visibility = Visibility.Hidden;
TabItem2.Visibility = Visibility.Hidden;
TabItem3.Visibility = Visibility.Hidden;
TabItem4.Visibility = Visibility.Hidden;
//
mainWindow = this;
ac_m.count();
}
示例5: buttonSiguiente_Click
private void buttonSiguiente_Click(object sender, EventArgs e)
{
if (opcion == 0)
{
System.IO.StreamWriter file = new System.IO.StreamWriter("BDL_ELYON.elyon", true);
file.WriteLine(obtenerDatos());
file.Flush();
file.Close();
string seguridad = "";
if (radioButtonSeguridadAlto.Checked == true) seguridad = "Alto";
if (radioButtonSeguridadMedio.Checked == true) seguridad = "Medio";
if (radioButtonSeguridadBajo.Checked == true) seguridad = "Bajo";
string text2 = textBoxUsuario.Text + "|" + textBoxContraseña.Text + "|" + textBoxNombre.Text + "|" + seguridad.ToString() + "|";
System.IO.StreamWriter file2 = new System.IO.StreamWriter("USU_ELYON.elyon", true);
file2.WriteLine(text2);
file2.Flush();
file2.Close();
PanelDatosPersonal panel = new PanelDatosPersonal(opcion,textBoxUsuario.Text, textBoxNombre.Text, textBoxEmailLaboral.Text, textBoxEmailPersonal.Text);
panel.Show();
this.Close();
}
if (opcion == 1)
{
editarArchivo(0, obtenerDatos());
PanelDatosPersonal panel = new PanelDatosPersonal(opcion, textBoxUsuario.Text, textBoxNombre.Text, textBoxEmailLaboral.Text, textBoxEmailPersonal.Text);
panel.Show();
this.Close();
}
}
示例6: Save
public void Save(string filename)
{
var cols = columns.OrderBy(kv => kv.Value).Select(kv => kv.Key).ToList();
using (var o = new System.IO.StreamWriter(filename))
{
// write header
{
var header = "";
var mid = "";
foreach (var col in cols)
{
header += mid+Escape(col);
mid = ";";
}
o.WriteLine(header);
}
// then rows
foreach (var row in rows)
{
var line = "";
var mid = "";
foreach (var col in cols)
{
var val = "";
if (row.ContainsKey(col)) val = row[col].ToString();
line += mid + Escape(val);
mid = ";";
}
o.WriteLine(line);
}
o.Flush();
o.Close();
}
}
示例7: printButton_Click
private void printButton_Click(object sender, EventArgs e)
{
// Printer IP Address and communication port
string ipAddress = printerIpText.Text;
int port = 9100;
try
{
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect(ipAddress, port);
// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(zplCode);
writer.Flush();
// Close Connection
writer.Close();
client.Close();
MessageBox.Show("Print Successful!", "Success");
this.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex);
MessageBox.Show("No printer installed corresponds to the IP address given", "No response");
}
}
示例8: WriteToLog
public static void WriteToLog(string logText, bool writeToLog)
{
try
{
if (writeToLog)
{
string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string path = System.IO.Path.Combine(myDocs, "pubnubmessaging.log");
lock (_logLock)
{
using (System.IO.TextWriter writer = new System.IO.StreamWriter(path, true))
{
writer.WriteLine(logText);
writer.Flush();
writer.Close();
}
}
}
}
catch (Exception ex)
{
try
{
string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string path = System.IO.Path.Combine(myDocs, "pubnubcrash.log");
using (System.IO.TextWriter writer = new System.IO.StreamWriter(path, true))
{
writer.WriteLine(ex.ToString());
writer.Flush();
writer.Close();
}
}
catch { }
}
}
示例9: filter_min_exp
public static void filter_min_exp(string [] args)
{
if(args.Length!=4)
{
ConsoleLog.WriteLine("checkbanned list out_list minexp");
return;
}
string[] Bots=System.IO.File.ReadAllLines(args[1]);
System.IO.TextWriter outs=new System.IO.StreamWriter(args[2],true);
//System.Net.WebClient client=new System.Net.WebClient();
NerZul.Core.Network.HttpClient client=new NerZul.Core.Network.HttpClient();
int cnt=1;
foreach (string Bot in Bots)
{
ConsoleLog.WriteLine("["+cnt.ToString()+"/"+Bots.Length.ToString()+"] "+
"Checking "+Bot.Split('|')[0]); cnt++;
string botinfo=Bot.Split('|')[0].Replace(" ","%20");
botinfo="http://api.erepublik.com/v1/feeds/citizens/"+botinfo+"?by_username=true";
botinfo=client.DownloadString(botinfo);
botinfo=System.Text.RegularExpressions.Regex.
Match(botinfo,@"\<experience-points\>(\w+)\<").Groups[1].Value;
if (int.Parse(botinfo)>=int.Parse(args[3]))
{
outs.WriteLine(Bot);
outs.Flush();
ConsoleLog.WriteLine("OK");
}
System.Threading.Thread.Sleep(3000);
};
}
示例10: connect
public static string connect(String server,int port,String ouath)
{
System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient ();
sock.Connect (server, port);
if (!sock.Connected) {
Console.Write ("not working hoe");
}
System.IO.TextWriter output;
System.IO.TextReader input;
output = new System.IO.StreamWriter (sock.GetStream ());
input = new System.IO.StreamReader (sock.GetStream ());
output.Write (
"PASS " + ouath + "\r\n" +
"NICK " + "Sail338" + "\r\n" +
"USER " + "Sail338" + "\r\n" +
"JOIN " + "#sail338" + "" + "\r\n"
);
output.Flush ();
for (String rep = input.ReadLine ();; rep = input.ReadLine ()) {
string[] splitted = rep.Split (':');
if (splitted.Length > 2) {
string potentialVote = splitted [2];
if (Array.Exists (validVotes, vote => vote.Equals(potentialVote)))
return potentialVote;
}
}
}
示例11: Plugin_EventXmlLoggerClass
public Plugin_EventXmlLoggerClass()
: base("Plugin_EventXmlLogger", "Plugin welches alle Events in einer XML-Datei mitloggt")
{
if (!System.IO.File.Exists("log\\Plugin_EventXmlLogger.xml"))
{
// Datei existiert nicht, anlegen
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("log\\Plugin_EventXmlLogger.xml", true, Encoding.UTF8))
{
sw.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\r<events>\n\r</events>\n\r");
sw.Flush();
sw.Close();
}
}
this.xmldoc = new XmlDocument();
try
{
this.xmldoc.Load("log\\Plugin_EventXmlLogger.xml");
}
catch (Exception ex)
{
// fehlerhaft beim laden
System.IO.File.Move("log\\Plugin_EventXmlLogger.xml", "log\\Plugin_EventXmlLogger_corrupt_" + DateTime.Now.Ticks + ".xml");
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("log\\Plugin_EventXmlLogger.xml", true, Encoding.UTF8))
{
sw.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\r<events>\n\r</events>\n\r");
sw.Flush();
sw.Close();
}
}
this.xmlroot = xmldoc.DocumentElement;
daedalusPluginBase.LogClass.evt_newLogMessage += new daedalusPluginBase.LogClass.evt_newLogMessageHandle(LogClass_evt_newLogMessage);
}
示例12: processLog
private void processLog(Object state)
{
_readWriteLock.EnterWriteLock();
while (queue.Count != 0)
{
string msg = String.Empty;
lock (_Lock)
{
if(queue.Count > 0)
msg = queue.Dequeue();
}
lock (_LockFile)
{
DateTime data = DateTime.Now;
file = new System.IO.StreamWriter(name + ".log", true);
if (file.BaseStream.Length > 1000000)
{
System.IO.File.Copy(name + ".log", name + "-" + data.ToString("ddMMyyyy HHmm") + ".log");
file.Flush();
file.Close(); //fechando arquivo para deletar
System.IO.File.Delete(name + ".log");
file = new System.IO.StreamWriter(name + ".log", true);
}
file.WriteLine(data.ToString(System.Globalization.CultureInfo.InvariantCulture) + " :" + msg);
file.Flush();
file.Close();
}
}
_readWriteLock.ExitWriteLock();
}
示例13: btnSave_Click
private void btnSave_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
try
{
dialog.DefaultExt = ".txt";
dialog.Filter = "Text Files|*.txt";
//dialog.FilterIndex = 0;
bool? dialogResult = dialog.ShowDialog();
if (dialogResult == false) return;
System.IO.Stream fileStream = dialog.OpenFile();
System.IO.StreamWriter sw = new System.IO.StreamWriter(fileStream);
foreach (StatusItem item in ViewModel.Current.Status.StatusItems)
{
sw.WriteLine(item.FormattedMesage );
}
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
示例14: writeGroup
/// <summary> <p>Creates source code for a Group and returns a GroupDef object that
/// describes the Group's name, optionality, repeatability. The source
/// code is written under the given directory.</p>
/// <p>The structures list may contain [] and {} pairs representing
/// nested groups and their optionality and repeastability. In these cases
/// this method is called recursively.</p>
/// <p>If the given structures list begins and ends with repetition and/or
/// optionality markers the repetition and optionality of the returned
/// GroupDef are set accordingly.</p>
/// </summary>
/// <param name="structures">a list of the structures that comprise this group - must
/// be at least 2 long
/// </param>
/// <param name="baseDirectory">the directory to which files should be written
/// </param>
/// <param name="message">the message to which this group belongs
/// </param>
/// <throws> HL7Exception if the repetition and optionality markers are not </throws>
/// <summary> properly nested.
/// </summary>
public static NuGenGroupDef writeGroup(NuGenStructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
{
//make base directory
if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
{
baseDirectory = baseDirectory + "/";
}
System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "group");
NuGenGroupDef group = getGroupDef(structures, groupName, baseDirectory, version, message);
System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).Encoding);
out_Renamed.Write(makePreamble(group, version));
out_Renamed.Write(makeConstructor(group, version));
NuGenStructureDef[] shallow = group.Structures;
for (int i = 0; i < shallow.Length; i++)
{
out_Renamed.Write(makeAccessor(group, i));
}
out_Renamed.Write("}\r\n");
out_Renamed.Flush();
out_Renamed.Close();
return group;
}
示例15: queue_task
public static string queue_task(string projectId, string token, string worker)
{
string uri = "https://worker-aws-us-east-1.iron.io:443/2/projects/" + projectId + "/tasks";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.ContentType = "application/json";
request.Headers.Add("Authorization", "OAuth " + token);
request.UserAgent = "IronMQ .Net Client";
request.Method = "POST";
// We hand code the JSON payload here. You can automatically convert it, if you prefer
string body = "{\"tasks\": [ { \"code_name\": \"" + worker + "\", \"payload\": \"{\\\"key\\\": \\\"value\\\", \\\"fruits\\\": [\\\"apples\\\", \\\"oranges\\\"]}\"} ] }";
if (body != null)
{
using (System.IO.StreamWriter write = new System.IO.StreamWriter(request.GetRequestStream()))
{
write.Write(body);
write.Flush();
}
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}