Form.Load does not execute all instructions ??

  • Thread starter Finn Stampe Mikkelsen
  • Start date
F

Finn Stampe Mikkelsen

I have this problem, that is driving me absolutely crazy...

My Form_Load does not execute clean/completely...

Let me explain what i mean.

Sometimes, i have a situation where my Form_Load eventhandler does not execute at all, so i tried to circumvent that by overloading
the WND_PROC to manually make sure that my Form_Load would execute. In case it allready had executed, it would simply return from
that possible extra call...

I since removed that overload.

Now i experience that my Form_Load does not run the entire structure. It just exits somewhere along the code, sometimes not even
running at all (Possibly due to the fact i removed my overload)...

There is no absolute point where the code exits out of the code... If i remove code from the handler, it might execute more of the
rest, but it is nopt always 1:1 with the lines of code i removed or added..

Can anyone explain to me what is ahppening here ??

Is there a limit to how much i can run in the Form_Load eventhandler (timewise) and if so, how can i make sure my initial code will
run before my UI comes to life?

I am absolute puzzeled over this and though i have tried to read up on it using google or other sources, i cannot find anything on
the matter..

/Finn
 
A

Arne Vajhøj

I have this problem, that is driving me absolutely crazy...

My Form_Load does not execute clean/completely...

Let me explain what i mean.

Sometimes, i have a situation where my Form_Load eventhandler does not
execute at all, so i tried to circumvent that by overloading the
WND_PROC to manually make sure that my Form_Load would execute. In case
it allready had executed, it would simply return from that possible
extra call...

I since removed that overload.

Now i experience that my Form_Load does not run the entire structure. It
just exits somewhere along the code, sometimes not even running at all
(Possibly due to the fact i removed my overload)...

There is no absolute point where the code exits out of the code... If i
remove code from the handler, it might execute more of the rest, but it
is nopt always 1:1 with the lines of code i removed or added..

Can anyone explain to me what is ahppening here ??

Is there a limit to how much i can run in the Form_Load eventhandler
(timewise) and if so, how can i make sure my initial code will run
before my UI comes to life?

I am absolute puzzeled over this and though i have tried to read up on
it using google or other sources, i cannot find anything on the matter..

If the method does not run to the end, then there must
either be a conditional return or an exception.

The first would be too obvious.

So my bet is on the exception. Put in a try catch
that logs exceptions to a log file.

Arne
 
F

Finn Stampe Mikkelsen

"Arne Vajhøj" skrev i meddelelsen news:[email protected]...
Is there a limit to how much i can run in the Form_Load eventhandler
(timewise) and if so, how can i make sure my initial code will run
before my UI comes to life?

I am absolute puzzeled over this and though i have tried to read up on
it using google or other sources, i cannot find anything on the matter..

If the method does not run to the end, then there must
either be a conditional return or an exception.

The first would be too obvious.

So my bet is on the exception. Put in a try catch
that logs exceptions to a log file.

Arne

I tend to agree with you, but 2 things...

1) Would an exception not cause the program to stop executing when run in debug mode?

2) Would an exception not be caused in the same statement or block of statements and not move back or forth depending on the amount
of code in the method?

And there is no conditional return anywhere in the method.. I have since my post tried to put the code into a seperate method, which
is then called by the timer_tick event. I created a timer, set the count to 10ms and enabled that timer at the end of my Form_Load
eventhandler. Now the entire code is run every time and is run in it's entirety...

This has for now solved my problem, but i'm no way closer to understanding why it was there in the first place..

/Finn
 
A

Arne Vajhøj

"Arne Vajhøj" skrev i meddelelsen


I tend to agree with you, but 2 things...

1) Would an exception not cause the program to stop executing when run
in debug mode?

2) Would an exception not be caused in the same statement or block of
statements and not move back or forth depending on the amount of code in
the method?

And there is no conditional return anywhere in the method.. I have since
my post tried to put the code into a seperate method, which is then
called by the timer_tick event. I created a timer, set the count to 10ms
and enabled that timer at the end of my Form_Load eventhandler. Now the
entire code is run every time and is run in it's entirety...

This has for now solved my problem, but i'm no way closer to
understanding why it was there in the first place..

catch(Exception) { }

is known to have created much grief.

If the problem moves around then I get associations to
multi threaded code with a concurrency bug in. That can
result in rather unpredictable errors.

I definitely does not like your workaround.

Arne
 
F

Finn Stampe Mikkelsen

"Arne Vajhøj" skrev i meddelelsen
"Arne Vajhøj" skrev i meddelelsen

This has for now solved my problem, but i'm no way closer to
understanding why it was there in the first place..

catch(Exception) { }

is known to have created much grief.

If the problem moves around then I get associations to
multi threaded code with a concurrency bug in. That can
result in rather unpredictable errors.

I definitely does not like your workaround.

Arne

I don't like it either, but i works...

I have found out some more though. The problem seems to center around some code where i update some ui-controls.

I have read up on it using google, at there seems to be a problem with just Form_Load prematurely showing the UI and exiting the
Form_Load eventhandler before the end of code.

I have been able to recreate that exact senario, where i had a situation of my code exitting before the end i a situation where i
updated a textbox control and it's Text property. As soon as i rewrote that code and did not update my UI-control until the end of
my method, it completed successfully.

I tried to move my code back from the earlier mentioned Timer_Tick method into the Form_Load metod and for now it seems to work
okay, but i'm not entirely sure, if the problem will not return at a later time.

Do you know of this ?? I had never heard of that before, but i could explain some of my problems. Not the one though, that my
Form_Load eventhandler sometimes does not execute at all. It's almost like the event is never fired. That is reported to be a issue
with FW2.0, but since my target framwork is 3.5 i assumed it was solved. Aparently not though, since i still need to do some work in
that area...

/Finn
 
A

Arne Vajhøj

"Arne Vajhøj" skrev i meddelelsen
I don't like it either, but i works...

I have found out some more though. The problem seems to center around
some code where i update some ui-controls.

I have read up on it using google, at there seems to be a problem with
just Form_Load prematurely showing the UI and exiting the Form_Load
eventhandler before the end of code.

I have been able to recreate that exact senario, where i had a situation
of my code exitting before the end i a situation where i updated a
textbox control and it's Text property. As soon as i rewrote that code
and did not update my UI-control until the end of my method, it
completed successfully.

I tried to move my code back from the earlier mentioned Timer_Tick
method into the Form_Load metod and for now it seems to work okay, but
i'm not entirely sure, if the problem will not return at a later time.

Do you know of this ?? I had never heard of that before, but i could
explain some of my problems. Not the one though, that my Form_Load
eventhandler sometimes does not execute at all. It's almost like the
event is never fired. That is reported to be a issue with FW2.0, but
since my target framwork is 3.5 i assumed it was solved. Aparently not
though, since i still need to do some work in that area...

I have no idea. Fundamentally I am GUI-ignorant.

Can you show a little example code that has the
problem?

That may trigger some suggestions for restructuring.

I am confident that the code can be made safe in a
good way by getting it structured properly.

Arne
 
R

Registered User

I don't like it either, but i works...

I have found out some more though. The problem seems to center around some code where i update some ui-controls.

I have read up on it using google, at there seems to be a problem with just Form_Load prematurely showing the UI and exiting the
Form_Load eventhandler before the end of code.

I have been able to recreate that exact senario, where i had a situation of my code exitting before the end i a situation where i
updated a textbox control and it's Text property. As soon as i rewrote that code and did not update my UI-control until the end of
my method, it completed successfully.

I tried to move my code back from the earlier mentioned Timer_Tick method into the Form_Load metod and for now it seems to work
okay, but i'm not entirely sure, if the problem will not return at a later time.

Do you know of this ?? I had never heard of that before, but i could explain some of my problems. Not the one though, that my
Form_Load eventhandler sometimes does not execute at all. It's almost like the event is never fired. That is reported to be a issue
with FW2.0, but since my target framwork is 3.5 i assumed it was solved. Aparently not though, since i still need to do some work in
that area...

Wrap some exception handling around the offending code before stepping
through the code. Examining the exception will provide some insight to
where/what the problem actually is.

It's not clear why these UI updates need to be done from within the
form's Load event handler. Is there some reason these UI control
properties can't be set from the form's constructor after the
InitializeComponent method returns?

regards
A.G.
 
F

Finn Stampe Mikkelsen

"Registered User" skrev i meddelelsen
Do you know of this ?? I had never heard of that before, but i could explain some of my problems. Not the one though, that my
Form_Load eventhandler sometimes does not execute at all. It's almost like the event is never fired. That is reported to be a issue
with FW2.0, but since my target framwork is 3.5 i assumed it was solved. Aparently not though, since i still need to do some work
in
that area...
Wrap some exception handling around the offending code before stepping
through the code. Examining the exception will provide some insight to
where/what the problem actually is.

The code does not throw any exception, so nothing to examine...

/Finn
 
F

Finn Stampe Mikkelsen

"Registered User" skrev i meddelelsen
"Registered User" skrev i meddelelsen



The code does not throw any exception, so nothing to examine...

Are you using a 64-bit system?
http://support.microsoft.com/kb/976038

regards
A.G.

As a matter of fact, Yes i am using a 64bit OS (Win7), but several things lead me to discard that as the reason...

First of all, i have experienced this since before i switced to 64bit OS and secondly the article/hotfix you refer to states, that
the application ends up generally unstable and throws a different exception at a later time, which as i understand it does halt the
execution of the code...

This is not the case with my app, so i'm not sure the 64bit scenario applies.. But antother info i'm gratefull to have and know
about...

/Finn
 

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

Top