0

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

Rahul Vishwakarma
  • 996
  • 5
  • 17
  • 35
Jordan Atkinson
  • 202
  • 1
  • 6
  • 24
  • This might get you started if it's toast you're looking for: http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET – DoctorMick Dec 30 '14 at 14:38
  • Well I haven't posted any comment or answer. Please give thanks to @DoctorMick. And what I assume from your question is that you want to show progress that Excel is writing. Your can show progress in the status bar. Since your form do only one thing i.e writing in excel, there is not point of doing multiple thread. Just show progress like 10 % complete, 20% complete... in the status bar. – Rahul Vishwakarma Dec 30 '14 at 14:55
  • Ah sorry, I didn't notice yours was the edit and not the suggestion. Thank you for the edit anyway, and thank you @DoctorMick for the suggestion :) – Jordan Atkinson Dec 30 '14 at 15:13

4 Answers4

0

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.

msporek
  • 1,187
  • 8
  • 21
  • Hi, @msporek. The process is ran on excel, I have no worries about blocking the UI and in fact I need it disabling to prevent the user altering a list which the data written resides. I had the message box appear followed by Microsoft Excel running in the background with my system telling it what to write, and then when it's finished, simply appears in front of the user. The user clicks the message box when it appears and then has a disabled/enabled form just sat there, depending on what how slow/fast the click the message box OK option. Id rather have a box appear throughout, closing at end. – Jordan Atkinson Dec 30 '14 at 14:45
  • If you run it as an external process, then you probably use the Process class to invoke the Excel operation, right? If that's the case, then you can use the Process.WaitForExit() to wait for the process to quit. Look here: http://msdn.microsoft.com/pl-pl/library/fb4aw7b8%28v=vs.110%29.aspx – msporek Dec 30 '14 at 14:48
0

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.

Jan Köhler
  • 5,817
  • 5
  • 26
  • 35
0

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

Community
  • 1
  • 1
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
0

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

Jordan Atkinson
  • 202
  • 1
  • 6
  • 24