using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static FileStream asyncfs =
new FileStream("ASyncTest.txt", FileMode.Open, FileAccess.Read, FileShare.None, 255, true);
static AsyncCallback callback = new AsyncCallback(CallBackFunction);
static byte[] readBuf = new byte[asyncfs.Length];
static void Main(string[] args)
{
asyncfs.BeginRead(readBuf, 0, readBuf.Length, callback, null);
for( int i=0; i<3; i++ )
{
Console.WriteLine("This is a Main() Loop Code - " + (i+1).ToString());
Thread.Sleep(1000);
}
asyncfs.Close();
}
static void CallBackFunction(IAsyncResult asyncResult)
{
int readB = asyncfs.EndRead(asyncResult);
if( readB > 0 )
{
asyncfs.Seek(0, SeekOrigin.Begin);
asyncfs.BeginRead(readBuf, 0, readBuf.Length, callback, null);
Console.WriteLine(Encoding.ASCII.GetString(readBuf, 0, readB));
Thread.Sleep(1000);
}
}
}
}
[출처] [C#] FileStream 비동기 입출력|작성자 씨피유
웹 크롤링 (0) | 2018.06.29 |
---|---|
yield (0) | 2018.06.29 |
대용량 txt 파일 짜르기 (0) | 2018.06.29 |
ENCODING / BITCONVERTER (0) | 2018.06.29 |
BinaryFormatter / XmlSerializer / DataContractJsonSerializer (0) | 2018.06.29 |