using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace IO_lab03
{
class Program
{
private static int temp;
static void Main(string[] args)
{
string filePath = @"C:Userss0163726sourcereposIO_lab03IO_lab03pliczek.txt";
FileStream fs
= new FileStream
(filePath, FileMode
.Open);
byte[] data
= new byte[1024];
IAsyncResult ar
= fs
.BeginRead(data,
0,
1024, myAsyncCallback,
new { Data
= data, Stream
= fs
});
IAsyncResult ar1
= fs
.BeginRead(data,
0,
1024, myAsyncCallback,
new { Data
= data, Stream
= fs
});
IAsyncResult ar2
= fs
.BeginRead(data,
0,
1024, myAsyncCallback,
new { Data
= data, Stream
= fs
});
IAsyncResult ar3
= fs
.BeginRead(data,
0,
1024, myAsyncCallback,
new { Data
= data, Stream
= fs
});
WaitHandle.WaitAll()
for (int i = 0; i < 100000; i++)
for (int j = 0; j < 100000; j++)
temp = i * j;
}
private static void myAsyncCallback(IAsyncResult ar)
{
dynamic args = ar.AsyncState;
byte[] data = args.Data;
FileStream fs = args.Stream;
int l = fs.EndRead(ar);
Console.WriteLine(ASCIIEncoding.ASCII.GetString(data).Substring(0, l));
}
public static async void ProcessRead()
{
string filePath = @"C:Userss0163726sourcereposIO_lab03IO_lab03pliczek.txt";
if (File.Exists(filePath) == false)
{
Console.WriteLine("file not found: " + filePath);
}
else
{
try
{
string text = await ReadTextAsync(filePath);
Console.WriteLine(text);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
private static async Task<string> ReadTextAsync(string filePath)
{
using (FileStream sourceStream
= new FileStream
(filePath,
FileMode.Open, FileAccess.Read, FileShare.Read,
bufferSize: 4096, useAsync: true))
{
StringBuilder sb
= new StringBuilder
();
byte[] buffer
= new byte[0x1000
];
int numRead;
while ((numRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
{
string text = Encoding.Unicode.GetString(buffer, 0, numRead);
sb.Append(text);
}
return sb.ToString();
}
}
}
}
Replies to Re: chuj
Title |
Name |
Language |
UNIX |
When |
Re: Re: chuj |
44 |
csharp |
1541597503 |
5 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}