Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server WinForm
In my Windows application, I have a save button, which takes 30-40 seconds to save data to SQL Server. So in the mean time, I want to display a message "saving... please wait" and after saving, this message should disappear.
 
Thanks in advance!
shashi
Posted 9-Apr-10 0:51am
Edited 9-Apr-10 5:25am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Since this is a Windows application, you probably already have at least one form visible. Rather than use a new window, you can place a label on the form that is already there. If you are working with an MDI application, then dock a StatusBar control along the bottom, and use a label there to provide feedback. Update the text at the start of your save process, then clear it when you are done. If there is more than one way to exit the save (because of error trapping, for example), you will want to clear the text before you ever exit.
 
Another thing users might find useful would be to call Cursor = Cursors.WaitCursor at the beginning and Cursor = Cursors.Default when done. When the user moves the mouse over your application, it will display the "doing something" cursor until the save has been completed. Again, you will want to make sure that the cursor is set back to the default before every exit.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Create a small form that has just that and remove the minimize, maximize and close buttons and make its size unchangeable, then write in your text. Now, at the start of the Save method, show this form as modal (ShowDialog()) and at the end of the save method, simply close it. Smile | :)
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can use From instance with single label showing you "Please wait" message.
 
When clicking on save button, you can show form with ShowDialog() method.
 
As SQL finishes saving data, using thread/delegate you can close the Message form. Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Showdialog method will not solve your purpose. The rest of the code will not get executed until you close the form. Rather try to make the form "Topmost" and display the form normally using .show only. After execution of the saving code, close the form.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

shashik1 wrote:
which takes 30-40 seconds

 
For an operation that takes this long, you have no option other than running it on a worker thread. If you run it on the UI thread, your form will become unresponsive.
 
This sounds like an ideal case for using a BackgroundWorker:
 
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]
 
Nick
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

I agree with Nick. When a process takes a long time, what you want to avoid is the user thinking that the program has frozen and then them killing the process from the Task Manager.
 
Since you indicated that it's a WinForms, you need to look into the StatusStrip control. You can add a StatusStrip at the bottom of your form. On that strip, you can add a Label and a ProgressBar.
 
Then, you can set the ProgressBar to Marquee style so that it will just continue to cycle and you can set a message that you are saving. Then, you start the save function on a BackgroundWorker.
 
Then just hook the RunWorkerCompleted event and set the form's cursor to the Wait cursor so that the user can't click anything else. Then, when the save is completed, you can set the StatusStrip's Visible property to false.
 
Doing it this way prevents the form from freezing and hopefully will prevent the user from trying to kill it.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 9 Apr 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid