I have 2 buttons name as "Build Start" and "Build Stop". what i want is when i click the stop button it will stop the execution of Building of all the projects. I have tried the Backgroundworker class but when i use the RunworkerAsync() function it will build only one project files and stop the execution thereafter. What could be the reason behind this and how to solve this problem.

I have an array of string which displays the list of all projects with .sln extension and i run through this array to build the project one by one that are inside the .sln file path. How to build all the .sln files and why all files are not building up when i use RunWorkerAsync().

Is there any way to implement this using threads.

What is happening right now is when i click the Build Start button the build continues but this does not allow me to click the Stop button to stop the Build Process.

I am attaching my code herewith:-

 private  BackgroundWorker backgroundWorker = new BackgroundWorker();
 public Form1()

        cmb_drive.SelectedItem = "Z";

     //   backgroundWorker.WorkerSupportsCancellation = true;

        backgroundWorker.WorkerReportsProgress = true;
        backgroundWorker.WorkerSupportsCancellation = true;

        backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);

         // backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
       // BackgroundWorker worker = sender as BackgroundWorker;

        if (checkbox1.Checked)


      private void bn_Start_Click(object sender, EventArgs e)
          private void bn_Stop_Click(object sender, EventArgs e)

       void function1()
        FOLDER1 = DRIVE + @":\Foldername1";

        LOGFILE1 = FOLDER1 + @"\Foldername2";

        Process msbuild;
        msbuild = new Process();

        DEVENV = Environment.GetEnvironmentVariable("VS100COMNTOOLS") + @"..\IDE\devenv.exe";

        var list = System.IO.Directory.GetFiles(LOGFILE1);
        foreach (var item in list)

        // Creation of array of string to Build Projects before Building Up.      

        array[0] = @"\make\versionupdate\versionupdate_vs2010.sln   /build  Release";

        for (int k = 0; k < array.Length; k++)

            this.lbl_CurrentProject.Text = "Current Project: " + @" " + array[k];

            msbuild.StartInfo.UseShellExecute = false;
            msbuild.StartInfo.CreateNoWindow = true;

            msbuild.StartInfo.Arguments = FOLDER1 + array[k] + @" /out " + LOGFILE1;
            msbuild.StartInfo.FileName = DEVENV;



Here is the code that i am executing but i cannot stop the process which is running in the function called when i click the stop button. where i am doing it wrong ?? Please do let me know.