Briskstar Technologies
Briskstar Technologies

Reputation: 2253

Displaying a progress bar or wait message

I want to display progress bar / wait message on any process in windows mobile. I tried displaying simple text "Please wait..." and wrote Application.DoEvents() but it is not displaying it nor progress bar.

Is there any way or other thing I need to follow to display progress bar in windows mobile device?

Upvotes: 0

Views: 4500

Answers (3)

Rosemol Francis
Rosemol Francis

Reputation: 25

Try this

    void StartLoadingPanel()
    {
        this.BeginInvoke((Action)delegate()
        { 
            Cursor.Current = Cursors.WaitCursor;
            loadingPanelContainer.Visible = true;


        });
    }

where loadingPanelContainer contain the text to be displayed.

Upvotes: 0

user153923
user153923

Reputation:

Use a Timer and place a static string in your project.

When you do not want text displayed, set the string value to null.

When a timer fires every 200 ms or so, update your message.

private static string message = null;

private void timer_Tick(object sender, EventArgs e) {
  if (String.IsNullOrEmpty(message)) {
    // clear your form values
  } else {
    // set your form values
  }
}

Of course, if you want a progress bar, you can do this too. Just make static int values for your progress bar and update your control when the timer ticks in the code snippet above.

This can be done with threads and event handlers, too, but a Timer (click to see code examples) is the simplest way.

UPDATE:

If you are doing this as inline code (as I understand from your comments), try the following:

private void Demo(int max) {
  label1.Text = String.Empty;
  progressBar1.Value = 0;
  progressBar1.Maximum = max;
  progressBar1.Refresh();
  do {
    progressBar1.Value++;
    progressBar1.Refresh();
    label1.Text = String.Format("{0}", progressBar1.Value);
    label1.Refresh();
  } while (progressBar1.Value < progressBar1.Maximum);
}

See if the code above does what you need.

NOTE: Oh, and get rid of Application.DoEvents(). It is an evil VB creation that encourages developers to have no idea what is going on.

Upvotes: 1

R Quijano
R Quijano

Reputation: 1301

The process you are running is blocking the UI thread?

Try to run your heavy processes on the thread pool.

Upvotes: 0

Related Questions