Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Basic4ppc Wishlist > Bug Reports
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Bug Reports Post about errors or bugs encountered.

AppStart behaviour

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-01-2010, 02:29 PM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 269
Awards Showcase
Beta Tester 
Total Awards: 1
Default AppStart behaviour

I'm unsure if a bug or not; but if AppClose is called in a Sub called from AppStart and I have a Form1_Close event Sub, when Sub Form1_Close has completed, execution is returned to and continues in AppStart. This only happens in Optimised Compiled applications. In the IDE or legacy copiled apps, it doesn't. This is how I thought it should behave.

Anyway, that was such a feeble explanation, I've attached some source that demonstrates what I'm trying to say.
Attached Files
File Type: sbp CloseTest.sbp (888 Bytes, 4 views)
Reply With Quote
  #2 (permalink)  
Old 01-01-2010, 04:38 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

When optimised compiled this is the startup sequence of calls in Basic4ppc sysntax
Code:
 Globals
 Main.App_start
 
If  ShownForm <> null Then
    Application.Run(ShownForm) <font color=
"SeaGreen">' this returns if AppClose is called within</font>
 End If <font color="seagreen">' the app terminates here</font>
Form1.Show doesn't actually Show Form1, it creates it and assigns it to ShownForm. The call to the .NET Application object Run method, passing it ShownForm as the main form of the application, actually creates the Windows Message queue for the application and draws the Form. AppClose actually translates to Form1.Close but until the message queue is created the Form cannot receive the Close message so the AppClose call is ignored.

There's a bit more going on than that but the general idea is correct. This sequence is why App_Start terminates the application if it completes without a Form being shown. There is no further code to execute so the application thread exits. If a Form is shown the application thread runs the message loop and stays alive till the application is closed and the message loop terminates.

In the IDE the startup is different as it is an interpreted environment. The interpreter sees the AppClose statement and does precisely that!

EDIT: The corollary to the above is to not perform a Form.Show until you know the application is to start. Then the behaviour should be the same in the IDE and when compiled.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 01-01-2010 at 04:48 PM.
Reply With Quote
  #3 (permalink)  
Old 01-02-2010, 11:27 AM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 269
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I didn't mention that this was for Desktop compilation. Its sometimes a dilema as to where to place the Form1.Show. If there is a lot of initialisation code in AppStart; showing the form early leaves it unresponsive until complete. Showing it late has your impatient users 'gunning' the application and you then have three instances of it open at the same time...

Here I have to show the form first, because I use Door to set MinimizeBox=True and MaximizeBox=False - they have to be applied to the form once its constructed. I also have a command line argument tha can set the form's WindowState to Minimized; if it is minimised, applying the MinimizeBox and MaximizeBox as above doesn't work.

The above is academic really as:
Quote:
The corollary to the above is to not perform a Form.Show until you know the application is to start. Then the behaviour should be the same in the IDE and when compiled.
If you move Form1.Show to the end of AppStart in my little example you get an error:

Error loading program.
Cannot access a disposed object.
Object name: 'CEnhancedForm'.


It stands to reason, because I've already killed it with the AppClose above. So the upshot is that in an Optimised Compiled application, all the code in AppStart has to run. This would normally go un-noticed, however it was brought to my attention as I have a logging file created in AppStart - that is not required if the application does not have to run.
Reply With Quote
  #4 (permalink)  
Old 01-02-2010, 11:54 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Zenerdiode View Post
So the upshot is that in an Optimised Compiled application, all the code in AppStart has to run
Yes, that is the implication of the startup code fragment that I posted above. You could set a global flag if any initialisation code invokes AppClose and test it in subsequent initialisation code to see whether to actually perform the initialisation or not bother.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange SQLite behaviour ghale Questions (Windows Mobile) 2 07-24-2009 03:56 PM
KeyPress event behaviour claudio Questions (Windows Mobile) 1 06-11-2009 08:26 AM
Different behaviour with ImageLibEx and FormLib klaus Beta Versions 5 04-29-2009 09:43 AM
Strange Form behaviour at start HARRY Questions (Windows Mobile) 2 12-31-2008 04:50 PM
Different behaviour DeskTop and Device HARRY Questions (Windows Mobile) 2 02-22-2008 01:36 PM


All times are GMT. The time now is 09:37 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0