Reputation: 202
I currently have a form which I am using. When a user presses export button, it exports some data to an excel worksheet. I have the process happening in the background and it doesn't visually show the user the excel worksheet while writing but does after.
On the c# form, when they click to export, I disable the form so that they cannot press anything on it. I would like there to be a message box or some sort of toast/indication that the excel is writing, and when the excel is finished, the message box/toast/indicator to close and allowing the user to continue.
At the moment the form is disabled, the excel written to, the form is then re-enabled. I have a message box appear using MessageBox.Show("text");
but it isn't really that elegant and looks shoddy.
Has anyone done anything similar and could point me into the right direction.
Thanks, J
Upvotes: 0
Views: 1415
Reputation: 202
Thanks for all your help,
I managed to work thous out myself in the end using a progress bar on win forms which increments as it writes to excel through my system, the current row in excel it writes to is the value on the progress bar, once its finished, the bar is full and I hide the bar :)
J
Upvotes: 0
Reputation: 13765
If you do not know how long it will take, use a wait / progress spinner, maybe in combination with a row counter that bumps up for each row or batch of 1000 rows depending in volumes. This way the user can see that it has not hung and should hopefully patiently wait for it to complete.
See this post: wpf loading spinner
Upvotes: 0
Reputation: 6030
You could add something like a StatusBar to the bottom of your form instead of the MessageBox. When the export begins, you can show the information on a label on that statusbar and remove it, when the export finishes. Additionally you can add a progressbar to that statusbar which indicates the status of the export progress.
Upvotes: 0
Reputation: 1197
I assume that the process that you are running is on the user interface Thread and not a separate Process (a separate application)?
You should follow up like this. First you show the MessageBox
or another dialog (you can use a form of your own design). Then you can use a BackgroundWorker
class / Thread
to initialize the time consuming work. This way the UI thread will not be blocked. Finally when the work is done, you close the dialog.
Upvotes: 0