本文整理汇总了C#中System.IO.StreamReader.ReadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader.ReadAsync方法的具体用法?C# System.IO.StreamReader.ReadAsync怎么用?C# System.IO.StreamReader.ReadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了System.IO.StreamReader.ReadAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectToTalkGadgetBind
//.........这里部分代码省略.........
//値は何でもおk。けど無いと死ぬ
{ "RID", "64438" },
//無くてもおk
{ "gsessionid", gsidVal },
{ "clid", clidVal },
//不変値。無くてもおk。
{ "VER", "8" },
{ "prop", "homepage" },
{ "AID", aidVal.ToString() },
{ "t", "1" },
{ "zx", "7anb33bhfgp2" },
{ "ec", "[\"ci:ec\",1,1,0,\"chat_wcs_20140612.120118_RC3\"]" },
})));
res = await PostStringAsync(
normalClient, url, new Dictionary<string, string>()
{
//reqXの数とcountの数を合わせないと死ぬ
{ "count", "1" },
{ "ofs", "0" },
{ "req0_m", "[\"connect-add-client\"]" },
{ "req0_c", clidVal },
{ "req0__sc", "c" },
}, tokenSource.Token);
DateTime debug_streamingTime;
while (true)
{
debug_streamingTime = DateTime.UtcNow;
tokenSource.Token.ThrowIfCancellationRequested();
//user streaming apiに接続する
//memo: 接続持続時間は3.5分が目安
url = new Uri(talkBaseUrl, string.Format("talkgadget/_/channel/bind?{0}",
await MakeQuery(new Dictionary<string, string>()
{
//無いと死ぬ
{ "RID", "rpc" },
{ "SID", sidVal },
{ "CI", "0" },
//無くてもおk
{ "clid", clidVal },//不要必要がちょっと微妙
{ "gsessionid", gsidVal },//接続更新でこいつが変化しているのは何故?
{ "AID", aidVal.ToString() },//無くても動くが、既読ページ数のようなものなので、正常動作には必要
//不変値。無くてもおk
{ "VER", "8" },
{ "prop", "homepage" },
{ "TYPE", "xmlhttp" },
{ "zx", "p5guamwzkeiu" },
{ "t", "1" },
{ "ec", "[\"ci:ec\",1,1,0,\"chat_wcs_20140612.120118_RC3\"]" },
})));
using (var strm = await GetStreamAsync(streamClient, url, tokenSource.Token))
using (var reader = new System.IO.StreamReader(strm, Encoding.UTF8))
{
var builder = new StringBuilder();
var buffer = new char[1024];
var buffCnt = 0;
var length = -1;
while (!reader.EndOfStream)
{
tokenSource.Token.ThrowIfCancellationRequested();
if (length < 0)
length = int.Parse(reader.ReadLine());
buffCnt = await reader.ReadAsync(buffer, 0, Math.Min(buffer.Length, length - builder.Length));
builder.Append(buffer, 0, buffCnt);
if (length == builder.Length)
{
var str = builder.ToString();
var replaced = ApiAccessorUtility.ConvertIntoValidJson(str);
var recieveJson = JToken.Parse(replaced);
//後始末
builder.Clear();
length = -1;
foreach (var item in recieveJson)
{
tokenSource.Token.ThrowIfCancellationRequested();
jsonReciever(item);
}
}
}
}
System.Diagnostics.Debug.WriteLine("DEBUG: StreamSessionTime\r\n{0}", DateTime.UtcNow - debug_streamingTime);
}
}
catch (Exception e)
{
if (tokenSource.Token.IsCancellationRequested)
subject.OnCompleted();
else
subject.OnError(e);
}
}, tokenSource.Token);
//購読中断時に呼び出してもらうメソッドを返す
return tokenSource.Cancel;
});
return observable;
}