Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: Turning of the monitors Pin
Heath Stewart30-Jul-04 4:23
protectorHeath Stewart30-Jul-04 4:23 
GeneralRe: Turning of the monitors Pin
PrebKlok30-Jul-04 4:53
PrebKlok30-Jul-04 4:53 
GeneralRe: Turning of the monitors Pin
Heath Stewart30-Jul-04 5:01
protectorHeath Stewart30-Jul-04 5:01 
GeneralAsynchronous Pin
sreejith ss nair29-Jul-04 2:17
sreejith ss nair29-Jul-04 2:17 
GeneralRe: Asynchronous Pin
SOCM_FP_CPP29-Jul-04 3:05
SOCM_FP_CPP29-Jul-04 3:05 
GeneralRe: Asynchronous Pin
Heath Stewart29-Jul-04 5:02
protectorHeath Stewart29-Jul-04 5:02 
GeneralRe: Asynchronous Pin
sreejith ss nair29-Jul-04 20:29
sreejith ss nair29-Jul-04 20:29 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 3:19
protectorHeath Stewart30-Jul-04 3:19 
The amount of time it takes to update your database is rather static (might differ a little due to various conditions). It's just that here your asynchronous call is executed and execution is returned immediately to the caller (your Form.Closing handler).

If this is not your main application Form, add the code to update the database elsewhere (perhaps on the original caller), as well as a way to get a deep copy of the data from the Form that is closing. Then execute the method asynchronously and the effect of the Form closing won't matter.

Also, for this Form - if not the main application form (i.e., that which is directly or indirectly passed to Application.Run) - if you use Form.Show, you don't need to dispose of the Form so don't - the async operation should run even though the form is hidden (depending on how you're accessing data that was input into the form). If you're using ShowDialog, then you're supposed to dispose your Form once you get what you need from it (otherwise you'll have a memory leak). In this case, you're back to what I said previous: you have to block at some point and wait for that async operation to complete with having done little else (i.e., the form was hidden), so there's really no point to using asynchronous operations, here.

A better design is to prompt the user to save before closing and take your time. This is what most other applications do. Open Microsoft Word, type a character or so and close the application - your prompted. Do the same with Notepad, Excel, AutoCAD, etc. Why not take this approach? At least the user no knows what's going on. Add that with a ProgressBar (perhaps a step for each record updated, depending on how you update your data source) and you'll have a much more user-friendly application.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 3:36
sreejith ss nair30-Jul-04 3:36 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 4:11
protectorHeath Stewart30-Jul-04 4:11 
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 4:21
sreejith ss nair30-Jul-04 4:21 
GeneralRe: Asynchronous Pin
Heath Stewart30-Jul-04 4:57
protectorHeath Stewart30-Jul-04 4:57 
GeneralRe: Asynchronous Pin
sreejith ss nair30-Jul-04 3:36
sreejith ss nair30-Jul-04 3:36 
GeneralRe: Asynchronous Pin
Tom Larsen29-Jul-04 5:42
Tom Larsen29-Jul-04 5:42 
GeneralQuestion on Porting Pin
SatyaDY29-Jul-04 0:40
SatyaDY29-Jul-04 0:40 
GeneralRe: Question on Porting Pin
Colin Angus Mackay29-Jul-04 0:45
Colin Angus Mackay29-Jul-04 0:45 
GeneralRe: Question on Porting Pin
SatyaDY29-Jul-04 17:54
SatyaDY29-Jul-04 17:54 
GeneralRe: Question on Porting Pin
Colin Angus Mackay29-Jul-04 20:41
Colin Angus Mackay29-Jul-04 20:41 
Generalseem to have a blackout Pin
Stephan Wright28-Jul-04 23:01
Stephan Wright28-Jul-04 23:01 
GeneralRe: seem to have a blackout Pin
Colin Angus Mackay28-Jul-04 23:38
Colin Angus Mackay28-Jul-04 23:38 
GeneralRe: seem to have a blackout Pin
Stephan Wright29-Jul-04 23:30
Stephan Wright29-Jul-04 23:30 
GeneralWav To Midi Pin
MicSky28-Jul-04 21:17
MicSky28-Jul-04 21:17 
GeneralRe: Wav To Midi Pin
Bret Mulvey9-Aug-04 18:13
Bret Mulvey9-Aug-04 18:13 
GeneralSimple yet unanswered question Pin
hatim_ali28-Jul-04 19:16
hatim_ali28-Jul-04 19:16 
GeneralRe: Simple yet unanswered question Pin
J. Dunlap28-Jul-04 19:30
J. Dunlap28-Jul-04 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.