Esempio n. 1
0
        private bool ThreadManagerExecuteAllThreads()
        {
            int iAwailableThreadCount = Properties.Settings.Default.iMaxWorkingThreads - ThreadList.Count;

            if (ulManagedAddress <= ulEndAddress)
            {
                while (true)
                {
                    if (iAwailableThreadCount > 0)
                    {
                        if (dbg.bDebugPrint) dbg.print(" iAwailableThreadCount =  " + iAwailableThreadCount.ToString());

                        UInt32 ulThreadsEndAddress = ulManagedAddress + ulSearchRangePerThread;
                        if (ulThreadsEndAddress > ulEndAddress)
                        {
                            ulThreadsEndAddress = ulEndAddress;
                        }
                        Properties.Settings.Default.PingTimeout = Convert.ToInt32(this.TextPingTimeout.Text);
                        Properties.Settings.Default.CheckPortTimeout = Convert.ToInt32(this.txtCeckPortTimeout.Text);
                        Properties.Settings.Default.chkShowAll = this.chkUsePing.Checked;
                        Properties.Settings.Default.bCheckPort = this.chkPorts.Checked;
                        Properties.Settings.Default.bScanPortRange = chkPortRange.Checked;
                        ui16StartPort = Convert.ToUInt16(this.text_StartPort.Text);
                        ui16EndPort = Convert.ToUInt16(this.text_EndPort.Text);

                        myScannerThreadClass ScannerThreadClass = new myScannerThreadClass();
                        if (dbg.bDebugPrint) dbg.print("ScannerThreadClass.StartThread(\n       StartAdress= " + StaticFunc.GetComputerFromIP(StaticFunc.GetIP(ulManagedAddress)) +
                                                                  ",\n     EndAdress= " + StaticFunc.GetComputerFromIP(StaticFunc.GetIP(ulThreadsEndAddress)) +
                                                                  ",\n     StartPort = " + ui16StartPort.ToString() +
                                                                  ",\n     EndPort = " + ui16EndPort.ToString() +
                                                                  ",\n     busePing = " + chkUsePing.Checked.ToString() +
                                                                  ",\n     PingTimoeut = " + Properties.Settings.Default.PingTimeout.ToString() +
                                                                  ",\n     CheckPortTimeout = " + Properties.Settings.Default.CheckPortTimeout.ToString() +
                                                                  ",\n     bScanPortRange = " + Properties.Settings.Default.bScanPortRange.ToString() +
                                                                  ",\n     bCheckPort = " + Properties.Settings.Default.bCheckPort.ToString() +
                                                                  ",\n      = Form_SearchMySQL_servers" +
                                                                  "\n)"
                                                                  );

                        if (ScannerThreadClass.StartThread(ulManagedAddress,
                                                           ulThreadsEndAddress,
                                                           ui16StartPort,
                                                           ui16EndPort,
                                                        Properties.Settings.Default.chkShowAll,
                                                        Properties.Settings.Default.PingTimeout,
                                                        Properties.Settings.Default.CheckPortTimeout,
                                                        Properties.Settings.Default.bScanPortRange,
                                                        Properties.Settings.Default.bCheckPort,
                                                        this))
                        {
                            if (dbg.bDebugPrint) dbg.print("ScannerThreadClass.ScannerThread.ManagedThreadId = " + ScannerThreadClass.ScannerThread.ManagedThreadId.ToString());
                            ThreadList.Add(ScannerThreadClass);
                            iAwailableThreadCount--;
                            ulManagedAddress = ulThreadsEndAddress + 1;
                            timer_follow_ScannerThread.Enabled = true;
                        }

                        if (ulManagedAddress > ulEndAddress)
                        {
                            if (dbg.bDebugPrint) dbg.print("NO iAwailableThreadCount ");
                            if (dbg.bDebugPrint) dbg.print("return false from ThreadManagerExecuteAllThreads");
                            return true;
                        }
                    }
                    else
                    {
                        if (ulManagedAddress > ulEndAddress)
                        {
                            if (dbg.bDebugPrint) dbg.print("Finished ");
                            if (dbg.bDebugPrint) dbg.print("return false from ThreadManagerExecuteAllThreads");
                            return true;
                        }
                        else
                        {
                            if (dbg.bDebugPrint) dbg.print("NO iAwailableThreadCount ");
                            if (dbg.bDebugPrint) dbg.print("return true from ThreadManagerExecuteAllThreads");
                            return false;
                        }
                    }
                }
            }
            return false;
        }
Esempio n. 2
0
 public bool SendMessage(myScannerThreadClass.eMessage eMsg)
 {
     foreach (myScannerThreadClass thrclass in ThreadList)
     {
         if (thrclass.bSend)
         {
             if (thrclass.mutexMessageBoxScanner.WaitOne(2000))
             {
                 thrclass.MessageList.Add(eMsg);
                 thrclass.mutexMessageBoxScanner.ReleaseMutex();
             }
             else
             {
                 return false;
             }
         }
     }
     return true;
 }