Toolbox items grayed out in VS 2010

I have tried numerous attempts to fix this problem or bug, firstly by deleting the .tbd files from C:\Users\\AppData\Local\Microsoft\VisualStudio\x.0

I have also tried this:

Visual Studio "Tools" menu "Options" submenu "Windows Form Designer" tab "General" tab Set "AutoToolboxPopulate" to "True"

The ToolBox list is still not populating correctly and the "BackgroundWorker" component I need is grayed out. Any ideas?

Upvotes: 0

Views: 7215

Answers (3)

I have found a solution to my problem, using the BackgroundWorker class in C# without using the component from the toolbox. In this case, I needed two seperate backgroundWorkers:

using System.Threading;

public partial class MainWindow : Window
    {
        private BackgroundWorker bw1 = new BackgroundWorker();
        private BackgroundWorker bw2 = new BackgroundWorker();

        public MainWindow()
        {
            InitializeComponent();

            bw1.WorkerReportsProgress = true;
            bw1.DoWork += new DoWorkEventHandler(bw1_DoWork);
            bw1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw1_RunWorkerCompleted);
            bw1.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);

            bw2.WorkerReportsProgress = true;
            bw2.DoWork += new DoWorkEventHandler(bw2_DoWork2);
            bw2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw2_RunWorkerCompleted);
            bw2.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);
        }


        private void bw1_DoWork(object sender, DoWorkEventArgs e)
        {
            StatsProcessor proc = new StatsProcessor();
            proc.CompareStats(listText1, listText2);    
        }

        private void bw2_DoWork2(object sender, DoWorkEventArgs e)
        {
            StatsParser parser = new StatsParser();
        }

        private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar2.IsIndeterminate = false;
            progressBar2.Value = 100;

            btnCompareStats.IsEnabled = true;

        }

        private void bw2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar1.IsIndeterminate = false;
            progressBar1.Value = 100;

            btnFetchStats.IsEnabled = true;
        }

        private void bw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar2.Value = e.ProgressPercentage;
        }

        private void bw2_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar1.Value = e.ProgressPercentage;
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            btnCompareStats.IsEnabled = false;

            StatsProcessor proc = new StatsProcessor();

            if (bw1.IsBusy != true)
                    {
                        progressBar2.IsIndeterminate = true;

                        // Start the asynchronous operation.
                        bw1.RunWorkerAsync();
                    }       

        }

        private void btnFetchStats_Click(object sender, RoutedEventArgs e)
        {
            btnFetchStats.IsEnabled = false;

            if (bw2.IsBusy != true)
                {
                       progressBar1.IsIndeterminate = true;

                       // Start the asynchronous operation.
                       bw2.RunWorkerAsync();
                }
        }
}

Upvotes: 1

eFloh
eFloh

Reputation: 2158

At least a workaround: declare the BackgroundWorker in code, but don't forget to dispose it properly:

public class MyForm : Form
{
  private BackgroundWorker bgWorker = null;

  public MyForm()
  {
    InitializeComponent();

    this.bgWorker = new BackgroundWorker; //TODO: set properties and event handlers
  }

  public override void Dispose(bool disposing)
  {
    //TODO: copy from MyForm.Designer.cs and add:
    Backgroundworker bgw = this.bgWorker;
    this.bgWorker = null;
    if (disposing && bgw != null)
    {
      try
      {
      //TODO: release event handlers
      bgw.Dispose();
      }
      catch(Exception)
      {
        /* consumed disposal error */
      }
    }
  }
}

Upvotes: 1

Spence
Spence

Reputation: 29360

I would try resetting the toolbox items. Then use the Add Item dialog to put back something you need.

Upvotes: 0

Related Questions