csharpener Posted August 11, 2003 Posted August 11, 2003 Hi all, Does anyone here know how or why a form will erratically disappear when disposing? I am developing a large app with various forms being accessed via calls like the one below: public static DialogResult getResult(ref int id) { MyForm form = new MyForm(); DialogResult dg = form.ShowDialog(); try { id = form.txtID.text; } catch(System.Exception ex) { Console.WriteLine(ex.Message); dg = DialogResult.Cancel; } form.Dispose(); return dg; } All the forms involved in the app have large numbers of textboxes, datagrids, datasets etc and all the update routines involved with a normal db app. The problem is when disposing any of these forms (for example after a user clicks an exit button) the form remains on screen for a second or two with a kind of washed-out look. When there is another form under the disposing one or a new form opening, the closing one makes the app look really slow and ugly... Is there some way to get rid of this behaviour? Thanks if you can help ...CS Quote
*Experts* mutant Posted August 11, 2003 *Experts* Posted August 11, 2003 (edited) Try to Close the form first using the Close() method of the form object. I tried using Dispose() on the form and I didnt notice anything like you described. Edited August 11, 2003 by mutant Quote
csharpener Posted August 12, 2003 Author Posted August 12, 2003 Thanks Mutant but that makes no visible difference. It was my understanding that the form.Close routine just invokes the form.closing event which in turn calls Dispose anyway. I think it may have something to do with the Validate routine (base) - investigating this but if anyone else has another idea please let me know... Cheers CS Quote
donnacha Posted August 13, 2003 Posted August 13, 2003 This is a very common problem with people and one that is difficult to fix, especiall if there is a lot of data in your forms. One thing to do is to ensure that as much of the init is done in the form.new event as opposed to the load event, this will speed up the display of the new form. Another thing you can do is to trap the form1.close event and in this before calling the form1.dispose, display the second form etc... Check also what compile option you are using, debug or release, debug is much slower on the form change, so try it on release and see what you get. If anybody finds a surebet way of doing this then let the world know. Quote Hamlet
csharpener Posted August 14, 2003 Author Posted August 14, 2003 thanks donnacha :) I was beginning to think I was the only one suffering from this problem... At least I now know I'm not alone L8R CS Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.