I am having troubles with progress bars.
This example below works but really is not the behavior I need.
This form allows me to pick an appointment date with the first method, getting the people for that day, then the next two methods fill in the details for an appointment.
What this sample above gives me is a rough progress bar as I go through each of the methods for ClassThatDoesWork. This is a crude estimate however.
What I cannot figure out is how to update the progress bar while I am doing work inside the individual methods of ClassThatDoesWork. For example, when I FillResultsArraywithDetails, I would like to update the progress bar each time I iterate through an appointment (get name 1 - update progress by 5%, get name 2 - update progress to 10%, now get appt1 details - update to 15%, appt2 details complete - update to 20%, .... until I'm done.) The percentages are arbitrary here, but it makes the example simpler.
thanks!
This example below works but really is not the behavior I need.
This form allows me to pick an appointment date with the first method, getting the people for that day, then the next two methods fill in the details for an appointment.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace CheckApptCalendar
{
public partial class Form1 : Form
{
public string apptDate;
public string database;
public string database1; // one practice
public string database2; // other practice
public Form1()
{
InitializeComponent();
dateTimePicker1.Value = (DateTime.Now);
}
public void button1_Click(object sender, EventArgs e)
{
smoothProgressBar1.Value = 0;
ThreadStart threadstart = dowork;
threadstart.BeginInvoke(null, null);
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
apptDate = dateTimePicker1.Value.ToString("yyyyMMdd");
}
public void smoothProgressBar1_Load(object sender, EventArgs e)
{
}
public void UpdateProgressBar()
{
if (smoothProgressBar1.InvokeRequired)
{
MethodInvoker updateProgressBar = UpdateProgressBar;
smoothProgressBar1.Invoke(updateProgressBar);
}
else
{
// i just put 5 in to see it work
smoothProgressBar1.Value = smoothProgressBar1.Value + 5;
}
}
public void dowork()
{
ClassThatDoesWork classthatdoeswork1 = new ClassThatDoesWork();
database1 = "database1";
UpdateProgressBar();
database2 = "database2";
apptDate = dateTimePicker1.Value.ToString("yyyyMMdd");
classthatdoeswork1.GetNumberOfAppointments(apptDate, database1, database2);
UpdateProgressBar();
classthatdoeswork1.FillResultsArraywithDetails(apptDate, database1);
UpdateProgressBar();
classthatdoeswork1.FillResultsArraywithDetails(apptDate, database2);
UpdateProgressBar();
ResultsView results = new ResultsView();
results.DisplayResultsTable(classthatdoeswork1.resultsTable);
results.ShowDialog();
}
}
}
What this sample above gives me is a rough progress bar as I go through each of the methods for ClassThatDoesWork. This is a crude estimate however.
What I cannot figure out is how to update the progress bar while I am doing work inside the individual methods of ClassThatDoesWork. For example, when I FillResultsArraywithDetails, I would like to update the progress bar each time I iterate through an appointment (get name 1 - update progress by 5%, get name 2 - update progress to 10%, now get appt1 details - update to 15%, appt2 details complete - update to 20%, .... until I'm done.) The percentages are arbitrary here, but it makes the example simpler.
thanks!