コード例 #1
0
        public void TaskSample()
        {
            Console.WriteLine("Task");
            Console.WriteLine("======");
            ParallelProcess parallelProcess = new ParallelProcess();

            Task[] tasks      = new Task[2];
            string taskName01 = "Tarea 01";
            string taskName02 = "Tarea 02";

            tasks[0] = Task.Factory.StartNew((Object obj) => {
                TaskParameter param = (TaskParameter)obj;
                parallelProcess.WriteProcess01(param.Name);
            }, new TaskParameter {
                Name = taskName01
            });

            tasks[1] = Task.Factory.StartNew((Object obj) => {
                TaskParameter param = (TaskParameter)obj;
                parallelProcess.WriteProcess02(param.Name);
            }, new TaskParameter {
                Name = taskName02
            });

            Task.WaitAll(tasks);
            //parallelProcess.WriteProcess01();
            //parallelProcess.WriteProcess02();
        }
コード例 #2
0
        public void StreamWriterSample()
        {
            Console.WriteLine("StreamWrite");
            Console.WriteLine("============");
            ParallelProcess parallelProcess = new ParallelProcess();

            StreamWriter sr = new StreamWriter("Writer.txt");

            sr.WriteLine("Texto 01");
            sr.WriteLine("Texto 02");
            sr.WriteLine("Texto 03");
            sr.Close();
        }
コード例 #3
0
        public void ThreadSample()
        {
            Console.WriteLine("Thread");
            Console.WriteLine("======");
            ParallelProcess parallelProcess = new ParallelProcess();

            Thread th1 = new Thread(new ThreadStart(parallelProcess.WriteProcess01));
            Thread th2 = new Thread(new ThreadStart(parallelProcess.WriteProcess02));

            th1.Start();
            th2.Start();

            //parallelProcess.WriteProcess01();
            //parallelProcess.WriteProcess02();
        }
コード例 #4
0
        public void StreamReaderSample()
        {
            Console.WriteLine("StreamReader");
            Console.WriteLine("============");
            ParallelProcess parallelProcess = new ParallelProcess();

            StreamReader sr = new StreamReader("Sample.txt");

            string line = sr.ReadLine();

            while (line != null)
            {
                Console.WriteLine(line);
                line = sr.ReadLine();
            }
        }