Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Suppose I have to install 10 MSi setup through automated process(setup path read from XML file) & from UI(Winform) I have to show progress through 2 progressbar. Where ProgressBar1 show progress of 1 by 1 MSi setup & ProgressBar2 show overall 10 MSi setup progress (I mean if 1 MSi setup will installed then ProgressBar2 should show 10%).

The main problem is how we manage first progressbar1 progress? Because it's system process. So how I manage progress of progressbar1 & pass value.


C#
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

    //Intall selected products one by one
    foreach (var productpath in _pim.SelectedProducts)
    {
        using (var mutex = new System.Threading.Mutex(false, "mutex01"))
        {
            mutex.WaitOne();
            try
            {
                    // Start installation process of a selected product
                    Process.Start(productpath);

                    // Todo : calculation of a product installation %
                    backgroundWorker1.ReportProgress(1);
            }
            catch (System.Threading.AbandonedMutexException ex) // Current thread owns the mutex, and must release it.
            {
                Console.WriteLine("Exception on return from WaitOne." + "\r\n\tMessage: {0}", ex.Message);
            }
            finally
            {
                mutex.ReleaseMutex();
                _installedproductcount += 1;
            }
        }
    }
}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
    label3.Text = e.ProgressPercentage.ToString() + "%";
}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    progressBar1.Value = 0;
    label3.Text = "0";
}
Posted
Updated 26-Aug-15 18:51pm
v3

1 solution

If I understand your question correctly, the progress bar 1 would monitor the progress of a single setup. In order to do that you would need to communicate with the Windows Installer through an API. Have a look at this article: Wrapping the Windows Installer 2.0 API[^]. The article itself is a bit old sou you probably need to modify the code to use newer version if installer. Refer for example to https://msdn.microsoft.com/en-us/library/aa370573(v=vs.85).aspx[^] and https://msdn.microsoft.com/en-us/library/aa368786(v=vs.85).aspx[^].

From progress bar 2 point of view each install would represent 10% of the overall progress so this should be fairly easy to handle.
 
Share this answer
 
Comments
S K Suman 27-Aug-15 1:26am    
Mika can you once review on my updated question please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900