本文整理汇总了C#中System.Text.UTF8Encoding.EndsWith方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.EndsWith方法的具体用法?C# UTF8Encoding.EndsWith怎么用?C# UTF8Encoding.EndsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.EndsWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAsync
/// <summary>
/// Read packets off the string asynchronously.
/// </summary>
/// <returns>Task that will make the read.</returns>
/// <see cref="http://stackoverflow.com/questions/4388771/difference-between-networkstream-read-and-networkstream-beginread"/>
/// <see cref="http://www.winsocketdotnetworkprogramming.com/threadingasynchronouspatterninnetwork3g.html"/>
/// <see cref="http://msdn.microsoft.com/en-us/library/dd997423.aspx"/>
/// <see cref="http://www.albahari.com/nutshell/cs4ch23.aspx"/>
public Task<string> ReadAsync()
{
byte[] buffer = new byte[5000];
// this will create a child task
Task<int> readTask = Task<int>.Factory.FromAsync(
this.networkStream.BeginRead, this.networkStream.EndRead,
buffer, 0, buffer.Length, null,
TaskCreationOptions.AttachedToParent);
// run this when the readtask is done
return readTask.ContinueWith((originalReadTask) =>
{
string data = new UTF8Encoding().GetString(buffer);
// there's possibly more than 5000 bytes to read, so get the next section of the response
string remaining = string.Empty;
if (!data.EndsWith("\0") && readTask.Result == buffer.Length)
{
remaining = Read();
}
return string.Concat(data, remaining);
}, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);
}