M
Mark Irvine
Hi,
I am making an async web service call and a progress bar that just loops
until the call is complete. Before I make the call I set a bool var to
false I the invoke the progress bar and while this var is false the bar
will continue to loop. When the call completes this var is set to true and
the progress bar is stopped and hidden. The probelm is that sometime it
crashes the emulator, however it has not yet crashed an actual pocket pc
device. As I am dealing with more than one thread I am using the Invoke
methods. The key code is included below:
private void btnDownloadSchedule_Click(object sender, System.EventArgs e)
{
this.btnDownloadSchedule.Enabled = false;
this.ShowProgressBar();
this.SetGotScheduleToFalse();
this.wsSchedule = new
Heat.IntelligentScheduler.Pda.App.wsHeatSchedule.Schedule();
this.wsSchedule.BeginGetSchedule(this.mScheduling.EngineerId,
this.GetDate().ToShortDateString(), wsHeatSchedule.JobPriority.All, new
AsyncCallback(ScheduleCallback), null);
}
private void ScheduleCallback(IAsyncResult iarSchedule)
{
try
{
this.wsSchedule.EndGetSchedule(iarSchedule, out this.xnHigh, out
this.xnAM, out this.xnPM);
this.mScheduling.AddScheduleData(this.xnHigh, JobPriority.All,
this.GetDate());
this.wsSchedule.Abort();
this.pbStatus.Invoke(new EventHandler(this.SetProgressMax));
this.SetGotScheduleToTrue();
this.HideProgressBar();
this.btnDownloadSchedule.Enabled = true;
}
catch(Exception ex)
{
MessageBoxes.ErrorMessageBox(ex.ToString(), "Here 2");
/*if(MessageBoxes.QuestionMessageBox("There ws a problem fulfilling your
last request, would you like to try again?", "Communication Failure : " +
ex.ToString()) == DialogResult.Yes)
{
//this.GetSchedule(DateTime.Parse(this.cboYear.SelectedValue.ToString()
+ "/" + this.cboMonth.SelectedValue.ToString() + "/" +
this.cboDay.SelectedValue.ToString()));
}*/
}
}
private DateTime GetDate()
{
return DateTime.Parse(this.cboYear.SelectedValue.ToString() + "/" +
this.cboMonth.SelectedValue.ToString() + "/" +
this.cboDay.SelectedValue.ToString());
}
public void UpdateProgressBar(object sender, EventArgs e)
{
while(!this.bolGotSchedule)
{
if(this.pbStatus.Value == this.pbStatus.Maximum)
{
this.pbStatus.Value = this.pbStatus.Minimum;
}
this.pbStatus.Value += 5;
Application.DoEvents();
}
}
public void SetProgressMax(object sender, EventArgs e)
{
this.pbStatus.Value = this.pbStatus.Maximum;
Application.DoEvents();
}
public void ShowProgressBar()
{
this.pbStatus.Invoke(new EventHandler(ShowProgressBar));
}
public void ShowProgressBar(object sender, EventArgs e)
{
this.pbStatus.Visible = true;
}
public void HideProgressBar()
{
this.pbStatus.Invoke(new EventHandler(HideProgressBar));
}
public void HideProgressBar(object sender, EventArgs e)
{
this.pbStatus.Visible = false;
}
public void SetGotScheduleToTrue()
{
this.Invoke(new EventHandler(SetGotScheduleToTrue));
}
public void SetGotScheduleToTrue(object sender, EventArgs e)
{
this.bolGotSchedule = true;
}
public void SetGotScheduleToFalse()
{
this.Invoke(new EventHandler(SetGotScheduleToFalse));
}
Although it has not crashed any devices, the app is still in development and
has not run that much on real devices. At the moment I think it is a glitch
with the emulator, but I would appreciate any feedback on the code.
Mark
I am making an async web service call and a progress bar that just loops
until the call is complete. Before I make the call I set a bool var to
false I the invoke the progress bar and while this var is false the bar
will continue to loop. When the call completes this var is set to true and
the progress bar is stopped and hidden. The probelm is that sometime it
crashes the emulator, however it has not yet crashed an actual pocket pc
device. As I am dealing with more than one thread I am using the Invoke
methods. The key code is included below:
private void btnDownloadSchedule_Click(object sender, System.EventArgs e)
{
this.btnDownloadSchedule.Enabled = false;
this.ShowProgressBar();
this.SetGotScheduleToFalse();
this.wsSchedule = new
Heat.IntelligentScheduler.Pda.App.wsHeatSchedule.Schedule();
this.wsSchedule.BeginGetSchedule(this.mScheduling.EngineerId,
this.GetDate().ToShortDateString(), wsHeatSchedule.JobPriority.All, new
AsyncCallback(ScheduleCallback), null);
}
private void ScheduleCallback(IAsyncResult iarSchedule)
{
try
{
this.wsSchedule.EndGetSchedule(iarSchedule, out this.xnHigh, out
this.xnAM, out this.xnPM);
this.mScheduling.AddScheduleData(this.xnHigh, JobPriority.All,
this.GetDate());
this.wsSchedule.Abort();
this.pbStatus.Invoke(new EventHandler(this.SetProgressMax));
this.SetGotScheduleToTrue();
this.HideProgressBar();
this.btnDownloadSchedule.Enabled = true;
}
catch(Exception ex)
{
MessageBoxes.ErrorMessageBox(ex.ToString(), "Here 2");
/*if(MessageBoxes.QuestionMessageBox("There ws a problem fulfilling your
last request, would you like to try again?", "Communication Failure : " +
ex.ToString()) == DialogResult.Yes)
{
//this.GetSchedule(DateTime.Parse(this.cboYear.SelectedValue.ToString()
+ "/" + this.cboMonth.SelectedValue.ToString() + "/" +
this.cboDay.SelectedValue.ToString()));
}*/
}
}
private DateTime GetDate()
{
return DateTime.Parse(this.cboYear.SelectedValue.ToString() + "/" +
this.cboMonth.SelectedValue.ToString() + "/" +
this.cboDay.SelectedValue.ToString());
}
public void UpdateProgressBar(object sender, EventArgs e)
{
while(!this.bolGotSchedule)
{
if(this.pbStatus.Value == this.pbStatus.Maximum)
{
this.pbStatus.Value = this.pbStatus.Minimum;
}
this.pbStatus.Value += 5;
Application.DoEvents();
}
}
public void SetProgressMax(object sender, EventArgs e)
{
this.pbStatus.Value = this.pbStatus.Maximum;
Application.DoEvents();
}
public void ShowProgressBar()
{
this.pbStatus.Invoke(new EventHandler(ShowProgressBar));
}
public void ShowProgressBar(object sender, EventArgs e)
{
this.pbStatus.Visible = true;
}
public void HideProgressBar()
{
this.pbStatus.Invoke(new EventHandler(HideProgressBar));
}
public void HideProgressBar(object sender, EventArgs e)
{
this.pbStatus.Visible = false;
}
public void SetGotScheduleToTrue()
{
this.Invoke(new EventHandler(SetGotScheduleToTrue));
}
public void SetGotScheduleToTrue(object sender, EventArgs e)
{
this.bolGotSchedule = true;
}
public void SetGotScheduleToFalse()
{
this.Invoke(new EventHandler(SetGotScheduleToFalse));
}
Although it has not crashed any devices, the app is still in development and
has not run that much on real devices. At the moment I think it is a glitch
with the emulator, but I would appreciate any feedback on the code.
Mark