How delay firing again

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I had it happen again today that I needed some code to run upon loading the
form but the code that I needed to have run needed to run AFTER all the rest
of Visual Studio's events had fired. Due to the fact that the Visual Studio
events continued to fire after I ran my code, it goofed things up. Isn't
there any way to fix it so that the code you want to run upon startup of a
form is insured to run only after VS has fired all it's events?
 
Woody,

What event handler do you currently have your code in, and what events are
firing after that eventhandler runs?

Kerry Moorman
 
What event is firing after your code? How does Visual Studio doesn't fire
events. If you just run the exe created Visual Studio isn't involved
anymore. I think your talking about the framework firing event, in which
case we need to know what is happening to mess you up. More info please.

Chris
 
If I understand your problem correctly, the fix is pretty simple.

Create a class level boolean variable in your form class.

Private m_IsLoading as boolean=true

Add this line as the first line inside your events that you don't want to
run while VS is initiailizing the form at startup.

Public Sub SomeEvent(s as sender, e as eventargs) handles blah.blah
If m_IsLoading = True Then Return
' rest of event code here...
End Sub

Then in your Form Load event set m_IsLoading=false.

This solved a lot of issues I had like this.

HTH,
Greg
 
Woody Splawn wrote...
I had it happen again today that I needed some code to run upon loading the
form but the code that I needed to have run needed to run AFTER all the rest
of Visual Studio's events had fired. Due to the fact that the Visual Studio
events continued to fire after I ran my code, it goofed things up. Isn't
there any way to fix it so that the code you want to run upon startup of a
form is insured to run only after VS has fired all it's events?

Sorry for the C# code but it is all I have:

private void OnAfterLoad()
{
// do stuff here you want done after form loads
}

private void ProgressDialog_Load(object sender, System.EventArgs e)
{
// form load code goes here
BeginInvoke(new MethodInvoker(OnAfterLoad));
label2.Text = "Finished loading form";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top