code crashes emulator

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
 
A

Alex Feinman [MVP]

Crashes how? Do you get a fault inside the emulator code, emulated OS or
your own app?
 
M

Mark Irvine

Alex,

Thanks for the reply. There is no error message. The app just stops
responding. The only way to get going again is to use the memory management
tool in settings or soft reset the emulator.

Mark
 
P

Paul G. Tobey [eMVP]

Are you sure that you aren't performing some synchronous network operation
from the user interface thread? If something took a long time to respond,
your UI would be 'dead' until you either got the response that you wanted or
the operation timed-out.

Paul T.
 
I

Ilya Tumanov [MS]

M

Mark Irvine

Paul,

I'm start an async call to a webservice, but that should automatically go on
another thread, is that correct?

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top