c # DirectoryEntry.Children Тайм-аут в Windows 10, но не в Windows 7 - PullRequest
0 голосов
/ 09 мая 2019

У меня есть простое приложение WinForms, целью которого является получение списка компьютеров, подключенных к локальной сети (все 4 компьютера подключены к коммутатору, нет внешнего подключения). На всех компьютерах отключены брандмауэры и включен общий доступ. Два компьютера Windows 7 и два Windows 10.
Это работает найти в Windows 7.

Все компьютеры могут видеть друг друга при просмотре сетевых папок, и есть папки общего доступа для просмотра.

Код

using System;
using System.IO;
using System.Windows.Forms;
using System.DirectoryServices; //included reference

namespace TestDirectory
{
    public partial class Form1: Form
    {
        Public form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            DirectoryEntry root = new DirectoryEntry("WinNT:");
            foreach(DirectoryEntry computers in root.Children)
            {
                foreach(DirectoryEntry computer in computers.Children)
                {
                    MessageBox.Show(computer.Name.ToString());
                    if(Directory.Exists(@"\\" + computer.Name + "rest of path"))
                    {
                       // Do something.
                    }
                }
            }
        }
    }
}

Ошибка

Строка с ошибками root.Children при попытке расширить представление результатов. Похоже, именно поэтому результаты не возвращаются.

Я попытался отключить параметр отладки. Программа не вызывает ошибку или сбой, но не возвращает результатов.

Evaluating the function 'System.Linq.systemCore_EnumerableDebugView.Items.get' timed out and needed to be aborted in an unsafe way. This may have corrupted the target process. If the problem happens regularly, consider disabling the Tools->Options settings 'Debugging->General->Enable property evaluation and other implicit function calls' or change the code to disable evaluation of this method. See help for information on doing this.

...