none
Make a messagebox stay till a function finishes executing RRS feed

  • Question

  • Hi All,

    I have a messagebox before a function starts, like this .

    Messagebox.show("Please wait till all links are verfied");//Make this stay till the below code gets completely executed ,if possible disable the ok button in the message box and enable it later or just disable the ok button and close the message box once the function gets executed

    foreach(word.hyperlink link in links)

    {

    try

    {

    //do something

    }

    catch

    {

    //do something

    }

    }

    Messagebox.show("All links are verified");

    Any ideas are appreciated.Thanks for your time :) 

    Monday, November 17, 2014 6:36 AM

Answers

  • Hello Apoorva,

    You need to run another thread for the long-running task. Thus, the UI thread will be free for displaying any dialogs.

    But in case of Office applications, it is not recommended to access their objects from another threads - most of them use the single-threaded apartment model.

    Monday, November 17, 2014 8:43 AM
  • Yes, there is. You can create a new dialog window without buttons.

    FYI MessageBoxes are just a set of prepared windows forms which you can configure passing parameters to the Show method.

    Monday, November 17, 2014 10:35 AM

All replies

  • Hello Apoorva,

    You need to run another thread for the long-running task. Thus, the UI thread will be free for displaying any dialogs.

    But in case of Office applications, it is not recommended to access their objects from another threads - most of them use the single-threaded apartment model.

    Monday, November 17, 2014 8:43 AM
  • Thanks Eugene this totally did the trick.We are not supposed to use threads I guess ,but there is no other way to achieve this ,also I'am thinking of starting  thread,display a wait message in while loop and then finally abort the thread after executing the actual function in my main thread.

    Is there a way to only display a text instead of giving the user an ok button in my messagebox? I looked up on almost all answers but could'nt find any .


    Monday, November 17, 2014 9:07 AM
  • Yes, there is. You can create a new dialog window without buttons.

    FYI MessageBoxes are just a set of prepared windows forms which you can configure passing parameters to the Show method.

    Monday, November 17, 2014 10:35 AM
  • Thanks a lot Eugene,

    I used a method like 

      public static class Prompt
            {
                public static void ShowDialog(string text, string caption)
                {
                    Form prompt = new Form();
                    prompt.Width = 350;
                    prompt.Height = 200;
                    prompt.Text = caption;
               Label textLabel = new Label() {  Width = 400,Text = "Pls wait" };
                     prompt.Controls.Add(textLabel);
                    prompt.ShowDialog();
          
                }
            }

    and call to this method like Prompt.ShowDialog("Test", "123"); Thanks a lot for your idea, I understood and learnt a lot cause of this. 

    Monday, November 17, 2014 4:58 PM