Проводник завершает процесс

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

CurrentDir = @"C:\Users\" + Environment.UserName + @"\Desktop\";
        try
        {
            Topmost = false;

            var proc = System.Diagnostics.Process.Start("explorer",CurrentDir + (sender as Button).ToolTip);



            //Здесь может понадобиться ожидание 
            System.Threading.Thread.Sleep(1000);
            if (proc.WaitForInputIdle(Convert.ToInt32(TimeSpan.FromSeconds(30).TotalMilliseconds)))
            {
                //Здесь тоже может понадобиться ожидание 
                System.Threading.Thread.Sleep(2000);
                proc.EnableRaisingEvents = true;
                proc.Exited += Proc_Exited;
                IntPtr handle = new WindowInteropHelper(this).Handle;
                SetParent(proc.MainWindowHandle, handle);
                Topmost = true;

                Button button = new Button();
                button.Height = 66;
                button.Width = 99;

                int i = Wrap1.Children.Count;

                Wrap1.Children.Add(button);

                (Wrap1.Children[i] as Button).Style = this.FindResource("GlassButton") as Style;
                (Wrap1.Children[i] as Button).ToolTip = (sender as Button).ToolTip;


                BitmapImage bit = new BitmapImage();
                bit.BeginInit();
                Uri u = new Uri(@"workspace\" + System.IO.Path.GetFileNameWithoutExtension((sender as Button).ToolTip.ToString()) + ".jpg", UriKind.RelativeOrAbsolute);
                bit.UriSource = u;
                bit.EndInit();
                ImageBrush image = new ImageBrush();
                image.ImageSource = bit;

                (Wrap1.Children[i] as Button).Background = image;
            }



           

        }
        catch(Exception ex)
        {

            MessageBox.Show(ex.ToString());
            
        }

Ответы (0 шт):