本文整理汇总了C#中System.IO.StreamWriter.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.WriteAsync方法的具体用法?C# System.IO.StreamWriter.WriteAsync怎么用?C# System.IO.StreamWriter.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了System.IO.StreamWriter.WriteAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: escribirMensaje
//Metodo hace la copia de seguridad
public void escribirMensaje()
{
int numFilas = dgvTabla.Rows.Count;//Cuenta el numero de filas que tiene la tabla
String txtOrigen = "";
String txtDestino = "";
String texto = "";
//crea el fichero
System.IO.StreamWriter file = new System.IO.StreamWriter(this.ruta, true);
//Crear objeto StringBuilder para escribir un texto
StringBuilder sb = new StringBuilder();
//Mientras la lista mensaje esta vacia
while( !lmsg.Is_Empty())
{
//devuelve el primer mensaje de la lista, con el origen,destino y el texto. Despues borra el msg de la lista
Mensaje msg = lmsg.Get_First();
txtOrigen=msg.getOrigen();
txtDestino = msg.getDestino();
texto = msg.getMensaje();
lmsg.Remove_First();
//Agregar mensaje al objeto
sb.AppendLine("Origen: " + txtOrigen + "#" + " Destino: " + txtDestino + "#" + " Texto: " + texto + "##");
}
//escribe el mensaje en el fichero de texto
file.WriteAsync(sb.ToString());
file.Close();
}
示例2: CreateAccent
public static void CreateAccent(string name, Color highlight, Color accent)
{
using (var sw = new System.IO.StreamWriter(System.IO.File.Create(System.IO.Path.Combine(MeCore.DataDirectory, "Color", name + ".xaml")))) {
string s = System.Windows.Markup.XamlWriter.Save(createResourceDictionary(highlight, accent));
System.Threading.Tasks.Task.WaitAll(sw.WriteAsync(s));
}
}
示例3: Execute
public override async Task Execute(IHttpRequestResponseContext context)
{
SetStatus(context);
context.Response.ContentLength64 = response.Length;
context.Response.SendChunked = false;
context.Response.ContentType = "text/html";
using (context.Response.OutputStream)
using (var tw = new System.IO.StreamWriter(context.Response.OutputStream, UTF8.WithoutBOM, 65536, true))
await tw.WriteAsync(response);
}
示例4: ExecuteRequestAsync
public async Task<HttpProgressInfo> ExecuteRequestAsync(string url, Dictionary<string,string> headers = null, string method = "GET", JToken body = null)
{
var pi = new HttpProgressInfo();
pi.Url = new Uri(url);
pi.Method = method;
pi.RequestHeaders = new WebHeaderCollection();
var req = WebRequest.CreateHttp(url);
req.Method = method;
if (headers != null)
{
foreach (var i in headers)
{
req.Headers.Add(i.Key, i.Value);
pi.RequestHeaders.Add(i.Key, i.Value);
}
}
pi.RequestBody = body == null ? null : body.DeepClone();
pi.RequestStarted = DateTime.UtcNow;
pi.State = HttpTransactionState.Started;
OnProgress(pi);
if (body != null)
{
using (var rs = await req.GetRequestStreamAsync())
using (var sw = new System.IO.StreamWriter(rs))
{
await sw.WriteAsync(body.ToString(Formatting.None));
}
}
pi.RequestCompleted = DateTime.UtcNow;
pi.State = HttpTransactionState.RequestSent;
OnProgress(pi);
var res = (HttpWebResponse)await req.GetResponseAsync();
pi.State = HttpTransactionState.HeadersReceived;
pi.ResponseStarted = DateTime.UtcNow;
pi.ResponseStatus = res.StatusCode;
pi.ResponseStatusDescription = res.StatusDescription;
pi.ResponseHeaders = res.Headers;
OnProgress(pi);
using (var rs = res.GetResponseStream())
using (var sr = new System.IO.StreamReader(rs, Encoding.UTF8))
{
var dataText = await sr.ReadToEndAsync();
pi.State = HttpTransactionState.Complete;
pi.ResponseCompleted = DateTime.UtcNow;
if (!string.IsNullOrWhiteSpace(dataText))
{
var tok = JToken.Parse(dataText);
pi.ResponseBody = tok;
}
}
OnProgress(pi);
return pi;
}