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);
}
}
}
}
'프로그래밍 > .Net' 카테고리의 다른 글
SYSTEM 에 의해서 파일이 잠기는 현상 (C# 빌드시 copy 불가 : error MSB3021) (0) | 2014.01.17 |
---|---|
EventLog 활용하기 (0) | 2014.01.17 |
XML 사용하여 특정 속성값 대체하기 (0) | 2014.01.17 |
Main UI Invoke 사용 (다중 thread 속성 false) (0) | 2014.01.17 |
InvokeRequire 사용하기 (0) | 2014.01.17 |