Пример #1
0
        private static void Main(string[] args)
        {
            //解析命令行参数
            ICommandLineParser parser
                = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(args, _opts))
            {
                Environment.Exit(1);
            }

            _root_node = new node {
                url = _opts._url_start
            };
            _dbm = new db_mgr(_opts._db_path, _opts._db_cache);

            //启动工作线程
            _thread_msg_dic = new Dictionary <Thread, string>(_opts._thread_cnt);
            for (int i = 0; i != _opts._thread_cnt; ++i)
            {
                Thread t = new Thread(t_work)
                {
                    IsBackground = true, Name = "t" + i
                };
                lock (_thread_msg_dic)
                    _thread_msg_dic.Add(t, "started");
                t.Start();
            }

            Console.Title = _heading_info;
            while (true)
            {
                Console.Clear();
                Console.WriteLine(_opts.create_helptext(_heading_info));
                Console.WriteLine();
                Process proc_self = Process.GetCurrentProcess();
                Console.WriteLine("working time: {0}", (DateTime.Now - proc_self.StartTime));
                Console.WriteLine("mem usage: {0} KB", (proc_self.WorkingSet64 / 1024).ToString("###,###"));
                Console.WriteLine("res downloaded:{0}\tres stored:{1}", prog_stat.res_downloaded, prog_stat.res_stored);
                Console.WriteLine("threads:");
                lock (_thread_msg_dic)
                {
                    foreach (KeyValuePair <Thread, string> kv in _thread_msg_dic)
                    {
                        Console.WriteLine(kv.Key.Name + "::" + kv.Value);
                    }
                }
                Thread.Sleep(1000);
            }
        }
Пример #2
0
        private static void Main(string[] args)
        {
            //解析命令行参数
            ICommandLineParser parser
                = new CommandLineParser(new CommandLineParserSettings(Console.Error));
            if (!parser.ParseArguments(args, _opts))
                Environment.Exit(1);

            _root_node = new node { url = _opts._url_start };
            _dbm = new db_mgr(_opts._db_path, _opts._db_cache);

            //启动工作线程
            _thread_msg_dic = new Dictionary<Thread, string>(_opts._thread_cnt);
            for (int i = 0; i != _opts._thread_cnt; ++i)
            {
                Thread t = new Thread(t_work) { IsBackground = true, Name = "t" + i };
                lock (_thread_msg_dic)
                    _thread_msg_dic.Add(t, "started");
                t.Start();
            }

            Console.Title = _heading_info;
            while (true)
            {
                Console.Clear();
                Console.WriteLine(_opts.create_helptext(_heading_info));
                Console.WriteLine();
                Process proc_self = Process.GetCurrentProcess();
                Console.WriteLine("working time: {0}", (DateTime.Now - proc_self.StartTime));
                Console.WriteLine("mem usage: {0} KB", (proc_self.WorkingSet64 / 1024).ToString("###,###"));
                Console.WriteLine("res downloaded:{0}\tres stored:{1}", prog_stat.res_downloaded, prog_stat.res_stored);
                Console.WriteLine("threads:");
                lock (_thread_msg_dic)
                {
                    foreach (KeyValuePair<Thread, string> kv in _thread_msg_dic)
                        Console.WriteLine(kv.Key.Name + "::" + kv.Value);
                }
                Thread.Sleep(1000);
            }
        }