[Gambas-devel] [WORKAROUND] BUG: gb2 & gb3 Failure to terminate

Benoît Minisini gambas at ...1...
Sat Dec 12 00:38:42 CET 2009


> 2009/12/12 Kadaitcha Man <nospam.nospam.nospam at ...176...>:
> > This one has had me banging my head against a brick wall.
> >
> > If the NEW keyword is used to instantiate a form in Sub Main() and the
> > form is never displayed then the application does not terminate.
> > Attached are two samples showing the same problem in both gb2 and gb3.
> >
> > This one has had me banging my head against a brick wall.
> >
> > If the NEW keyword is used to instantiate a form in Sub Main() and the
> > form is never displayed then the application does not terminate.
> > Attached are two samples showing the same problem in both gb2 and gb3.
> >
> > It is reasonable to create a form instance in anticipation of certain
> > conditions then to decide not to show the form and instead have the
> > application terminate immediately if certain conditions are or are not
> > met.
> 
> To workaround this issue, do not instantiate the form with the NEW
> keyword until it is known that the form will be shown. For example:
> 
> Public Sub Main()
> 
>   Dim fMain As Form
>   Dim bOkToStart As Boolean
> 
>   bOkToStart = CheckOkToStart()
> 
>   If bOkToStart Then
>     fMain = New fSomeForm
>     fMain.Show
>   Endif
> 
> End
> 
> Again, the above workaround applies to both gb2 and gb3.
> 

Here is how it works:

When the Main() function terminates, the event loop is started.

The event loop runs as long as:
  - There is a Process that runs.
  - There is a Timer that is enabled.
  - There is a File that is watched.
  - There is a Window that is opened. 

But I realized that sometimes, if you create a window, then you don't want to 
show it immediately. 

So the last constraint became:

  - There is a toplevel Window that was created.

I added a warning in the help topic related to the event loop to explain that 
specific point.

But maybe I will be able to change that behaviour in Gambas 3. Something like: 
the first time a Window is created, it won't be taken into account by the 
event loop, but as soon as it has been made visible, it will. Even if the 
window is hidden after.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list