English 中文(简体)
任务.FromAsync(BeginRead, EndRead)在完成之前就读到整个数据组?
原标题:Does Task.Factory.FromAsync(BeginRead, EndRead) read the entire data block before completing?

In my code right now I have something like this:

state.BytesRead += readPacket.Result;

if (state.BytesRead < state.Data.Length)
{
    Read(state);
}
else
{
    nextRead(state);
}

然而,我注意到,第一个声明从未生效。 我试图做这样的事情,看看我是否甚至可以有以下条件:

tcpClient.SendBufferSize = 16;
tcpClient.ReceiveBufferSize = 16;

但是,它从来不行。 我在客户和服务器之间发送了大量数据(显示超高和高;长1 000个特性),但条件从来都没有。 它只想一劳永逸地读写。

Is this because I am using Task.Factory.FromAsync and that it only completes upon reading in all the bytes? Here is the line of code that invokes the code snippet at the top of my post:

Task<int>.Factory.FromAsync(state.Stream.BeginRead, state.Stream.EndRead, state.Data, state.BytesRead, state.Data.Length - state.BytesRead, state);

我在从Ataync和所有辅导员之前都使用过同步的警示,以便进行所要求的检查,如果在接下来的读完所有 by子之前都读过。 难道这已不再需要从Ataync那里? 它现在是否自动处理?

最佳回答

Task.Factory.FromAsync, 仅就先前作为Eync BeginXXX/EndXXX pairs而存在的笔记。 由于这些方法只是按框架加以总结和援引,而不是由你明确援引,因此这些方法的运作方法将保持不变。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签