I am a beginner and was hoping someone could tell me if i am using the correct way to use a if/else while using threads.
On my form the user has a checkbox which will determine which set of apps that will be installed. If the users select wireless enabled it installs the odyssey client.
please don't eat me alive i am just starting out.
So question's being:
on the if/else statement is that best way?
How can i Invoke the check box control? I understood how to make the progressbar work by invoking but confused about the check box.
- Is this best way to hook up progressbar considering i am dealing with wceload>? Or is it possible to hook it up with out pre set values. I.E 25; 35 %?
thankyou
namespace Program1 { public partial class Form1 : Form {
private Thread myThread;
delegate void UpdateProgressDelegate();
private bool workerThreadDone;
public Form1()
{
InitializeComponent();
}
public string Message = "";
private void Form1_Load(object sender, EventArgs e)
{
}
delegate void UpdateStatusInvoker(string statusText);
private void MyWorkerThread()
{
while (!workerThreadDone)
{
Thread.Sleep(1000);
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"Software\Apps\Microsoft .NET CF 3.5"))
if ((Key != null && checkBox2.Checked))
{
MessageBox.Show("Framework Exist, Wireless apps Enabled");
appcenter();
oac();
}
else
if ((Key != null && !checkBox2.Checked))
{
MessageBox.Show("Framework exist and NOT installing wireless apps.");
appcenter();
}
else
if (checkBox2.Checked)
{
MessageBox.Show("Framework not found,Installing with wireless");
NETCFv351();
NETCFv352();
sqlce1();
sqlce2();
sqlce3();
appcenter();
oac();
}
else
if (!checkBox2.Checked)
{
MessageBox.Show("Installing everything with NO wireless");
NETCFv351();
NETCFv352();
sqlce1();
sqlce2();
sqlce3();
appcenter();
}
}
}
public void skipframework_progress()
{
this.statusBar1.Text = ("Framework Found!, Skipping");
this.progressBar1.Value = 35;
}
// NETCFv35.Messages.EN.wm.cab
public void NETCFv351()
{
this.progressBar1.Invoke(new UpdateProgressDelegate(framework_progress));
Thread.Sleep(1000);
string cab = "\\Program Files\\cabs\\NETCFv351.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
public void framework_progress()
{
this.statusBar1.Text = ("Installing NET3.5 Framework");
this.progressBar1.Value = 10;
}
//NETCFv35.Messages.EN.wm.cab
public void NETCFv352()
{
string cab = "\\Program Files\\cabs\\NETCFv352.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
//sqlce.ppc.wce5.armv4i.CAB
public void sqlce1()
{
string cab = "\\Program Files\\cabs\\sqlce1.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
//sqlce.repl.ppc.wce5.armv4i.CAB
public void sqlce2()
{
string cab = "\\Program Files\\cabs\\sqlce2.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
public void sqlce3()
{
//sqlce.dev.ENU.ppc.wce5.armv4i.CAB
string cab = "\\Program Files\\cabs\\sqlce3.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
Thread.Sleep(1000);
this.progressBar1.Invoke(new UpdateProgressDelegate(framework_done_progress));
}
public void framework_done_progress()
{
this.statusBar1.Text = ("NET3.5 Framework Installed");
this.progressBar1.Value = 30;
}
public void appcenter()
{
string cab = "\\Program Files\\cabs\\appcenter.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
Thread.Sleep(700);
ProcessStartInfo psi1 = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi1;
p.Start();
p.WaitForExit();
Thread.Sleep(700);
this.progressBar1.Invoke(new UpdateProgressDelegate(appcenter_progress));
}
public void appcenter_progress()
{
this.statusBar1.Text = ("Appcenter Installed");
this.progressBar1.Value = 35;
}
public void oac()
{
string cab = "\\Program Files\\cabs\\oac.cab";
string parm = @"/delete 1 """ + cab + @""" /silent";
ProcessStartInfo psi1 = new ProcessStartInfo(@"wceload.exe", parm);
Process p = new Process();
p.StartInfo = psi1;
p.Start();
p.WaitForExit();
Thread.Sleep(700);
this.progressBar1.Invoke(new UpdateProgressDelegate(oac_progress));
}
public void oac_progress()
{
this.statusBar1.Text = ("Odyssey Installed");
this.progressBar1.Value = 65;
}
private void button1_Click_1(object sender, EventArgs e)
{
workerThreadDone = false;
myThread = new Thread(MyWorkerThread);
myThread.IsBackground = true;
myThread.Start();
}
}
}