public void RunAdNetworkDiscovery()
        {
            if (discoverer == null || discoverer.IsDiscoverComplete)
            {
                // prepare to start the LDAP Discovery
                LdapNetworkDiscovery ldapDiscovery = new LdapNetworkDiscovery();
                //ActiveDirectoryNetworkDiscovery ldapDiscovery = new ActiveDirectoryNetworkDiscovery();
                discoverer = ldapDiscovery;
                discoverer.NetworkDiscoveryUpdate += new EventHandler <DiscoveryUpdateEventArgs>(discoverer_NetworkDiscoveryUpdate);
                NetworkDiscoveryTabView tabView = workItem.Items[Properties.Settings.Default.NetworkDiscoveryTabView] as NetworkDiscoveryTabView;
                base.SetTabView(tabView);

                // Start the discovery
                tabView.ShowStart();
                FireNetworkDiscoveryStarted();
                discoverer.Start();

                // LDAP discovery has completed
                tabView.ShowComplete();
                FireNetworkDiscoveryComplete(discoverer.ComputerList);
            }
            else
            {
                MessageBox.Show("There is another Network Discovery in progress. Please wait until Network Discovery is complete before starting another.", "Network Discovery", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        void discoverer_NetworkDiscoveryUpdate(object sender, DiscoveryUpdateEventArgs e)
        {
            lock (this)
            {
                NetworkDiscoveryTabView tabView = workItem.Items[Properties.Settings.Default.NetworkDiscoveryTabView] as NetworkDiscoveryTabView;
                string statusText = "Discovering domain, " + e.Domain + "...";
                if (!e.IsDomainOnly)
                {
                    statusText = "Discovered Asset, " + e.Domain + "\\" + e.Computer;
                }

                tabView.DeviceType     = e.Domain;
                tabView.StatusText     = statusText;
                tabView.DiscoveryCount = e.DiscoveredComputerCount;
                tabView.ProgressCount  = e.ProgressCount;
                tabView.FoundCounter   = e.Computer;

                tabView.ShowUpdate();
            }
        }
        private void BeginThreadedNetworkDiscovery(NetworkDiscovery instance)
        {
            if (discoveryThread.ThreadState == ThreadState.Running)
            {
                return;
            }

            discoverer = null;
            discoverer = instance;
            discoverer.NetworkDiscoveryUpdate += new EventHandler <DiscoveryUpdateEventArgs>(discoverer_NetworkDiscoveryUpdate);
            if (instance.CanRunInOwnThread)
            {
                if (changeView)
                {
                    NetworkDiscoveryTabView tabView = workItem.Items[Properties.Settings.Default.NetworkDiscoveryTabView] as NetworkDiscoveryTabView;
                    if (tabView != null)
                    {
                        base.SetTabView(tabView);
                    }
                }

                discoveryThread.Start();
            }
        }
        private void RunThreadedNetworkDiscovery()
        {
            if (discoverer.CanRunInOwnThread)
            {
                // start the discovery
                NetworkDiscoveryTabView tabView = workItem.Items[Properties.Settings.Default.NetworkDiscoveryTabView] as NetworkDiscoveryTabView;
                if (tabView != null)
                {
                    tabView.ShowStart();
                }
                discoverer.Start();

                if (runBothDiscovery)
                {
                    SNMPDiscovery snmpDiscovery = new SNMPDiscovery(Utility.GetSNMPIpRanges());
                    discoverer = snmpDiscovery;

                    //tabView.ShowStart();
                    discoverer.Start();
                }

                // discover has completed...update subscribers and TabView
                if (tabView != null)
                {
                    tabView.ShowComplete();
                }

                // +8.3.3
                // Did we complete an SNMP Discovery?
                if (discoverer is SNMPDiscovery)
                {
                    // Yes - we need to check whether or not the current scanner is configured to upload audits to an FTP
                    // site as in this case we need to create audit files for any assets discovered
                    AuditScannerDefinition auditScannerDefinition = null;
                    try
                    {
                        string scannerPath = Path.Combine(Application.StartupPath, "scanners") + "\\default.xml";
                        auditScannerDefinition = AuditWizardSerialization.DeserializeObject(scannerPath);
                    }
                    catch (Exception)
                    {
                    }

                    // 8.3.4 - CMD
                    //
                    // If we found a scanner and it defines an FTP upload of audit files then process this
                    // Note that we support either Upload to FTP Location or Audit to FTP which are flagged differently in the scanner
                    if ((auditScannerDefinition != null) &&
                        (auditScannerDefinition.FTPCopyToNetwork || auditScannerDefinition.UploadSetting == AuditScannerDefinition.eUploadSetting.ftp))
                    {
                        ((SNMPDiscovery)discoverer).UploadDiscoveredAssets(auditScannerDefinition);
                    }
                }

                // -8.3.3
                FireNetworkDiscoveryComplete(discoverer.ComputerList);
                discoveryThread = new Thread(new ThreadStart(RunThreadedNetworkDiscovery));
                discoverer.NetworkDiscoveryUpdate -= discoverer_NetworkDiscoveryUpdate;
                discoverer = null;
            }
        }