| |
// / This HTML file was produced by the ProjectPublisher WebService, By Asaf Shelly / //
// / WebService URL is: http://Services.AsyncOp.com/ProjectPublisher/ProjectPublisherWSvc.asmx / //
// / Learn more and find the source code here: http://AsyncOp.com / //
void User()
{
ReadAsync("C:\\temp\\temp.txt", 1000);
}
void ReadAsync(string ___path___, int ___timeout___)
{
FileStream fs = new FileStream(___path___, FileMode.OpenOrCreate);
ManualResetEvent manualEvent = new ManualResetEvent(false);
byte[] buffer = new byte[256];
IAsyncResult asyncResult = fs.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadCompletion), manualEvent);
manualEvent.WaitOne(___timeout___, false);
if (asyncResult.IsCompleted)
{
int numberOfBytesRead = fs.EndRead(asyncResult);
}
else fs.Close(); // Abort
}
static void OnReadCompletion(IAsyncResult asyncResult)
{
(asyncResult.AsyncState as ManualResetEvent).Set();
}
|
|
|