Пример #1
0
        async static void TestReadingFile(string fileName)
        {
            Console.WriteLine("---- about to read -------");

            await MinhAwesomeUtility.ReadFileNoBlocking(fileName, (contents) =>
            {
                using (var streamReader = new StreamReader(new MemoryStream(contents)))
                {
                    string s = streamReader.ReadToEnd();
                    Console.WriteLine($"file contents: {s}");
                }

                System.Diagnostics.Debug.WriteLine($"thread: {Thread.CurrentThread.ManagedThreadId}");
            });

            Console.WriteLine("---- finished reading ------");
        }
Пример #2
0
        async static void TestDownload()
        {
            await MinhAwesomeUtility.DownloadSite("http://www.cccis.com").
            ContinueWith((bytes) =>
            {
                System.Diagnostics.Debug.WriteLine($"thread: {Thread.CurrentThread.ManagedThreadId}");

                using (var streamReader = new StreamReader(new MemoryStream(bytes.Result)))
                {
                    string s = streamReader.ReadToEnd();
                    Console.WriteLine($"site content: {s}");
                }
            });

            //System.Diagnostics.Debug.WriteLine($"thread: {Thread.CurrentThread.ManagedThreadId}");

            //byte[] contents = await MinhAwesomeUtility.DownloadSite("http://www.cccis.com");

            //using (var streamReader = new StreamReader(new MemoryStream(contents)))
            //{
            //    string s = streamReader.ReadToEnd();
            //    Console.WriteLine($"site content: {s}");
            //}
        }