Show a wait message when an application exits

I have the following code: several times ArchiveFiles () takes longer to complete its execution.

When the user clicks the Exit button more than once from the context menu, the application stops responding if ArchiveFiles () takes longer. How can I show a wait message when he presses the "Exit" button again?

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
    ArchiveFiles(); 
    Application.Exit();
}

Thanks
Bhaskar

+3
source share
3 answers

WaitingForm .gif , . :

enter image description here

  private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  {
     using (var wait = new WaitingForm())
     {
       wait.Show();
       ArchiveFiles(); 
       Application.Exit();
     }
  }

, . , , wait.ShowDialog(); ArchiveFiles(); Application.Exit(); ( ).

+4

ArchiveFiles , thread , delegate BeginInvoke.

You should use some kind of synchronization object, for example ManualResetEvent, so the main thread will not execute when calling Application.Exit(). Or you can use some event to find out when the operation will end, and then call Application.Exit()(or call it inside ArchiveFiles), but I think it will be worse.

+2
source

All Articles