Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted (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 by mutant
Posted

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

Posted

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.

Hamlet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...