非同步資料流的處理

http://msdn.microsoft.com/zh-tw/magazine/cc337900.aspx

其實寫了應用程式之後,發現UI真的是處處非同步啊~

重點在這裡,有遞迴呼叫的fu:

AsyncCallback rc = readResult =>
{
    int read = source.EndRead(readResult);
    if (read > 0)
    {
        destination.BeginWrite(buffer, 0, read, writeResult =>
        {
            destination.EndWrite(writeResult);
            source.BeginRead(buffer, 0, buffer.Length, rc, null);
        }
    }
}
source.BeginRead(buffer, 0, buffer.Length, rc, null);

延伸使用:http://msdn.microsoft.com/zh-tw/magazine/cc700359.aspx

This entry was posted in 電腦和網際網路. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s