0

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?

ctacke
  • 66,480
  • 18
  • 94
  • 155
k-s
  • 2,192
  • 11
  • 39
  • 73
  • It would be helpful if you can provide more info than that ... let's see your code and we'll figure out what you're not doing properly. – BonanzaDriver Jul 17 '12 at 14:09

3 Answers3

1

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.

  • Thanks for your reply. I want to show Progress Bar on button click event. First I try to visible animated progress gif when process is start and hide that when process is completed. But it is not changing my User Interface when button event Process is going on. Same happens for progress Bar.User Interface change only after button event completed. And I want to show Progress Bar while Button event process is going on. – k-s Jul 18 '12 at 14:20
  • From your comment above, I'm guessing you are doing all of this in a single thread. You either need to execute your code in a separate thread and invoke updates to the progress bar or use a timer to update the progress bar. –  Jul 18 '12 at 15:53
  • Yeah, It is on single thread. Is there anything I can do async call or something related? Because my process thread is started and other thread of displaying progress bar is not coming in picture which cause problem. – k-s Jul 19 '12 at 06:47
  • From the sounds of your comments, you need the `Refresh()` method, not `Application.DoEvents()` See my update above. –  Jul 19 '12 at 16:29
  • Yes, Let me try with your code but it seems not to be work. I am confused at point that I am starting my thread so how other thread of progress bar (or loading message) integrated from separate thread. – k-s Jul 20 '12 at 06:12
  • Maybe you should post your code. It is hard for me to see what you are doing wrong when I haven't seen any code. If the code is too large to post, maybe you should create a very small test project with a progress bar and just the basic code. If it works, your problem can probably be seen by looking at the differences. If it does not work, post that code with the errors or unexpected behavior you get. –  Jul 20 '12 at 14:12
  • System.Threading.Thread.Sleep(2000); lblMessage.Text = "Images uploading, please wait..."; lblMessage.Refresh(); Application.DoEvents(); This is code I used and it is not refreshing label on button click. – k-s Jul 24 '12 at 13:58
0

The process you are running is blocking the UI thread?

Try to run your heavy processes on the thread pool.

R Quijano
  • 1,301
  • 9
  • 10
0

Try this

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


        });
    }

where loadingPanelContainer contain the text to be displayed.

Rosemol Francis
  • 25
  • 1
  • 1
  • 7