Example #1
0
 static void Main()
 {
     //Application.EnableVisualStyles();
     //Application.SetCompatibleTextRenderingDefault(false);
     //Application.Run(new Form1());
     AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e)
     {
         Console.WriteLine(e);
     };
     DnsLookuper d = new DnsLookuper("");
     List<string> s = d.CheckOut();
     List<string> r = new List<string>();
     ThreadPooler.ThreadPooler tp = new ThreadPooler.ThreadPooler(40);
     foreach (string k in s)
     {
         FuncationCaller f = new FuncationCaller();
         f.Arguments = new object[] { k };
         f.CallBack = delegate(FuncationCaller x, ResultEventArg e)
         {
             if (!((bool)e.Result))
             {
                 r.Add(x.Arguments[0].ToString());
             }
         };
         f.Funcation = delegate(object[] b)
         {
             //string d = string.Format("{0}{1}", b[0]);
             string dx = b[0].ToString();
             try
             {
                 ResolveState ioContext = new ResolveState(dx);
                 ManualResetEvent state = new ManualResetEvent(false);
                 state.Reset();
                 Dns.BeginGetHostEntry(ioContext.host, delegate(IAsyncResult ar)
                 {
                     ioContext = (ResolveState)ar.AsyncState;
                     try
                     {
                         ioContext.IPs = Dns.EndGetHostEntry(ar);
                     }
                     catch (Exception ce)
                     {
                         string u = string.Format("{0}:{1}", dx, ce.Message);
                         Console.WriteLine(u);
                         r.Add(u);
                     }
                     state.Set();
                 }, ioContext);
                 state.WaitOne();
                 string sr = "";
                 if (ioContext.IPs.AddressList.Length > 0)
                 {
                     foreach (var item in ioContext.IPs.AddressList)
                     {
                         sr += "," + item.ToString();
                     }
                 }
                 else
                 {
                     sr = "no ip found;";
                 }
                 Console.WriteLine("{0}:{1}", dx, sr);
                 return true;
             }
             catch (Exception ce)
             {
                 string u = string.Format("{0}:{1}", dx, ce.Message);
                 System.Diagnostics.Debug.Print(u);
                 //Console.WriteLine(u);
                 //r.Add(u);
                 //dom.Add(d);
                 return false;
             }
         };
         tp.AddFunction(f);
     }
     tp.Run();
     Console.ReadKey();
 }
Example #2
0
 public void AddFunction(FuncationCaller f)
 {
     mbrCallers.Enqueue(f);
 }
Example #3
0
 public void Run(FuncationCaller f)
 {
     AddFunction(f);
     r(f);
 }
Example #4
0
 public bool BindFun(FuncationCaller f)
 {
     if (IsBusy)
     {
         return false;
     }
     if (f == mbrFun)
     {
         return true;
     }
     mbrFun = f;
     //BackgroundWorker k = Worker;
     Worker.DoWork +=
         new DoWorkEventHandler(k_DoWork);
     Worker.ProgressChanged += new ProgressChangedEventHandler(k_ProgressChanged);
     EventInfo ei = Worker.GetType().GetEvent("RunWorkerCompleted");
     RunWorkerCompletedEventHandler rh = null;
     rh =
         delegate(object o, RunWorkerCompletedEventArgs e)
         {
             ResultEventArg xe = new ResultEventArg(e);
             (f.CallBack as CompletedDelegate)(f, xe);
             Worker.DoWork -= new DoWorkEventHandler(k_DoWork);
             Worker.ProgressChanged -= new ProgressChangedEventHandler(k_ProgressChanged);
             ei.RemoveEventHandler(Worker, rh);
             //mbrFinshed.Enqueue(w);
             object xo = Events[mbrEvtFinshed];
             if (xo == null)
             {
                 return;
             }
             (xo as EventHandler<ResultEventArg>)(this, xe);
         };
     ei.AddEventHandler(Worker, rh);
     Worker.RunWorkerAsync(f);
     return true;
 }