Beginner question

  • Thread starter Thread starter Christian Soltenborn
  • Start date Start date
C

Christian Soltenborn

Hi folks,

I'm from the Java world, and I want to play a little bit with VB .NET. I
have a simple question: In Java it is kind of common to have a static
main method which does nothing else then creating an object of the class
it belongs to and then to fall asleep. All real work will be done in the
object. If the program quits, it does this with System.exit(int).

How do I do something like this in VB .NET? I have source like this:

Public Shared Sub Main()
Dim controller = New Controller
End Sub

And, as I expected, the program creates the controller object and then
ends immediately.

I would like to learn how to avoid the "sudden death" :-) of my program,
and I would also like to know the similar method to Java's System.exit()!

Thanks in advance,
Christian
 
Hi Christian,

You mean something as this?

Cor

\\\contributed by Herfried K. Wagner
Public Module AppMain
Private m_AppMainForm() As MainForm
Public ReadOnly Property AppMainForm() As MainForm
Get
Return m_AppMainForm
End Get
End Property
Public Sub Main()
m_AppMainForm = New MainForm()
Application.Run(m_AppMainForm)
End Sub
End Module
///
 
* Christian Soltenborn said:
I would like to learn how to avoid the "sudden death" :-) of my
program, and I would also like to know the similar method to Java's
System.exit()!

In addition to Cor's reply: 'Application.Exit',
'Application.ExitThread'.
 
Cor said:
Hi Christian,

You mean something as this?

Cor

\\\contributed by Herfried K. Wagner
Public Module AppMain
Private m_AppMainForm() As MainForm
Public ReadOnly Property AppMainForm() As MainForm
Get
Return m_AppMainForm
End Get
End Property
Public Sub Main()
m_AppMainForm = New MainForm()
Application.Run(m_AppMainForm)
End Sub
End Module
///

Hi Cor,

no, actually not. I just had a look in the help, and the object passed
in the .Run method must inherit from Form (is you indicated). My
Controller class doesn't inherit fro anything (except Object). The
reason is that I have to implement a 3-tier design with a Controller
class, several Gui classes and a DataAccess class (it's for the university).

I try to describe it a little bit more precise: The Controller class
contains the Shared Sub Main. There a controller object will be created.
In the constructor, a gui object will be created, and it gets the
controller object passed as a reference. If th user does anything with
the gui, the gui calls the belonging controller method.

The Shared Sub main should (imho) just contain 2 or 3 lines: the
constructor call for the controller object and a statement like "wait
here forever (or until e.g. Application.exit() is called), but don't eat
processor time". Do you guys know what I mean?

Cu later,
Christian
 
Christian,
class, several Gui classes and a DataAccess class (it's for the
university).

By GUI class do you mean a Windows Form?

I would consider having a Run method on your Controller Class. This method
would call Application.Run. Then your Sub Main would be

Read the help on Application.Run

Alternatively you could have your Controller class inherit from
ApplicationContext, then you Sub Main would be:

Again read the help on Application.Run to see if this second model works
better for you.

The third alternative is to call Application.Run without any parameters, I
would do this in a method of the Controller class, similar to the first or
after creating the controller.

Again read the help on Application.Run to see if this third model works
better for you.
The Shared Sub main should (imho) just contain 2 or 3 lines: the
constructor call for the controller object and a statement like "wait
here forever (or until e.g. Application.exit() is called), but don't eat
processor time". Do you guys know what I mean?

That is of the purposes of Application.Run method. The other being to allow
your Windows forms to behave properly.

Hope this helps
Jay
 
Hi Jay and the other guys,

thanks a lot for your help! Jay's mail had exactly what I needed.
Sometimes it's just useless to search in the help if you don't know what
keywords to search for...

One more question: I didn't find anything about block comments in VB
..NET. That is, actually I found that VB doesn't have them, but I was not
sure if they have maybe been introduced in .NET!?
The reason I need them is that we use a cvs repository to coordinate our
coding, and I would like to use those nice cvs features like $Log$, $Id$
etc. in our code. Is there any way to do this?

Thanks,
Christian
 
Back
Top