
Winform, Accessing new Form causes lockup
Posted Wednesday, 17 February, 2010 - 18:20 by lagwagon23 inI have a popup child form that the user can input the size of the grid they want and enable LOD. they can change these values:
public struct NewValues { public int intMapsize; public int intStep; public int intY; public bool boolLOD; }
When I call a new window the form locks up. I figure this has to do with me passing an instance of the Parent form to the new form while the Paint event is running like so:
// Parent Form menu click private void newProjectToolStripMenuItem_Click(object sender, EventArgs e) { SubForms.frmNew frm = new SubForms.frmNew(this); frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); } //this is how I initialize the child form public partial class frmNew : Form { Form1 frm = new Form1(); public frmNew(Form1 frm1) { frm = frm1; InitializeComponent(); }
I was able to stop the app from locking up by threading the function that calls the new app. Would you recommend doing it like that? Can I pause the paint event so I don't have to thread for performance?


Comments
Re: Winform, Accessing new Form causes lockup
lol, tough crowd. did you not read a book about this in college? I won't share my solution with you, b/c I'm a made man. I never got any help in college with n00b questions like this. kill yourself.
Re: Winform, Accessing new Form causes lockup
This was uncalled for, DonPElbers.
This doesn't look right, you are creating two new forms here (one frmNew and one frm) then replace frm with frm1 (which means frm is leaked). I'm not sure what you are trying to do, but this should work:
Re: Winform, Accessing new Form causes lockup
Hi Fiddler,
I am opening a child form on my map editor that I can change the size of the terrain with. I need to alter the Parent forms X and Z coordinate values through the child form. I had passed "this" so I could access the parent form variables on the child form and alter them at run time, but it caused freeze up. Your way doesn;'t cause freeze up anymore, but I can access the parent form variables can I? Thanks for your time :P
Re: Winform, Accessing new Form causes lockup
There are many ways to solve this issue. For example:
Of course, this will only work if the parent actually is of type Form1 (otherwise you'll get a runtime exception.)
Your original approach would also work, as long as you call
Show(this)instead ofShowDialog()(the latter creates a modal message loop that temporarily stops the parent from receiving messages.)Re: Winform, Accessing new Form causes lockup
Thanks that fixed it.