English 中文(简体)
如果给网络Stream写信,则按规定进行。
原标题:Should writes to NetworkStream be performed asynchronously

鉴于NetworkStream.Write()是一种封闭式电话,如SendMessage(,即为进行书面操作创造新的通道,或者SendMessage(>,直至发出电文或出现例外情况为止?

我的格乌特告诉我,阻止这一方法是合理的,但是,看一下

PS:我知道Aync版本的写作、阅读等,但发现IsyncResult令人困惑,目前正在利用这些选择。

最佳回答

如果您在问询表上打电话SendMessage(),则该编码将予以阻挡,你的申请将“冻结”。 不要在你希望发送数据时制造新的线索,而是使用<代码>。 ThreadPool. QueueUserItem(o => SendMessage()) or Task.Factory.Start New(() => SendMessage() from rel=“noreferer” 任务平行图书馆,载于NET4.0。

如果你的申请为客户服务,并且你为每个客户提供新的校对,那么,如果你不希望做其他工作,同时向客户发送数据,那么<代码>SendMessage(<>>>>>可阻挡。

为每个客户建立一个新的通道有了一个缺陷:许多read子将消耗大量资源,这些read子的大部分时间将id,同时可以为其他客户提供服务。 如果你希望建立高性能服务器应用程序,你就应当了解同步的方案拟订情况。

http://msdn.microsoft.com/en-us/vstudio/gg316360“rel=“noretinger”>Async CTP。 谨请你写一下像同步法则,不出现令人厌恶的s。

public async void SendMessage()
{
    try {
        await socket.WriteAsync(buffer, 0, buffer.Length);
    } catch (...) {
        // handle it
   }
}

如今,SendMessage(SendMessage)赢得了 block,因为它会像往常一样被处决,而且根本看不出ary!

问题回答




相关问题
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. ...

热门标签