using System; using System.Text; using System.Threading; using System.IO; namespace zad1 { class Program { delegate long DelegateType(long arguments); static DelegateType delegateLong; static void Main(string[] args) { FileStream fs; Console.WriteLine("Zad6"); byte[] buffer = new byte[128]; using (fs = new FileStream("C:\\Users\\s0163841\\Desktop\\file.txt", FileMode.Open)) { AutoResetEvent are = new AutoResetEvent(false); fs.BeginRead(buffer, 0, buffer.Length, AsyncCallback, new { Stream = fs, Data = buffer, AutoResetEvent = are }); double q = 0.0001; for (int i = 0; i < 100000; i++) { q *= 1.0001; } are.WaitOne(); fs.Close(); } Console.WriteLine("\n\nZad7"); fs = new FileStream("C:\\Users\\s0163841\\Desktop\\file.txt", FileMode.Open); buffer = new byte[128]; var state = fs.BeginRead(buffer, 0, buffer.Length, null, null); Console.WriteLine("State: " + state); double m = 0.0001; for (int i = 0; i < 100000; i++) { m *= 1.0001; } fs.EndRead(state); fs.Close(); Console.WriteLine(Encoding.ASCII.GetString(buffer)); Console.WriteLine("\n\nZad7"); long result; IAsyncResult ar; long n = 50; //fibr delegateLong = new DelegateType(FibR); ar = delegateLong.BeginInvoke(n, null, null); result = delegateLong.EndInvoke(ar); Console.WriteLine("Fibr " + result); //fibi delegateLong = new DelegateType(FibI); ar = delegateLong.BeginInvoke(n, null, null); result = delegateLong.EndInvoke(ar); Console.WriteLine("Fibi " + result); //edgr delegateLong = new DelegateType(EdgR); ar = delegateLong.BeginInvoke(n, null, null); result = delegateLong.EndInvoke(ar); Console.WriteLine("EdgR " + result); //edgi delegateLong = new DelegateType(EdgI); ar = delegateLong.BeginInvoke(n, null, null); result = delegateLong.EndInvoke(ar); Console.WriteLine("EdgI " + result); Console.WriteLine("\nend"); Console.ReadKey(); } public static long FibR(long n) { if (n == 0) { return 0; } else if (n == 1) { return 1; } else { return (FibR(n - 1) + FibR(n - 2)); } } public static long FibI(long n) { long a = 0; long b = 1; for (long i = 0; i < n; i++) { long temp = a; a = b; b = temp + b; } return a; } public static long EdgR(long number) { if (number <= 1) return 1; else return number + EdgR(number - 1); } public static long EdgI(long n) { if (n <= 1) return 1; long result = 1; for (long i = 2; i <= n; i++) { result = result + i; } return result; } static void ThreadProc(Object stateInfo) { } static void AsyncCallback(IAsyncResult state) { dynamic args = state.AsyncState; FileStream fs = args.Stream; byte[] data = args.Data; AutoResetEvent are = args.AutoResetEvent; int l = fs.EndRead(state); //drukowanie tegfo co zostaƂo przeczytane Console.WriteLine(Encoding.ASCII.GetString(data)); are.Set(); } } }