newbie question, 1.0 and 1.1

M

medhanush

I have vb.net 1.0 book and wokring on vb.net 1.1 version
book says, there is Sub Main with attriubte STAThread in Form1, but I
don't see it in vs.net generated code and also
event handling for button click, book says, the form of delegate +=,
but vs.net using "Handles" keyword.

and,i looked at exe using ildasm, exe has shared sub Main.

can sb pl tell me, where vs.net writing sub Main and any url that
identifies differences of vb.net 1.0 and 1.1.
i wud appreciate your help

thanks
MeDhanush
 
W

wooster11

I don't ever recall .NET 1.0 generating the Sub Main for you. And I
definitely know that 1.1 does so. It's easy enough to add though.
This is what I do.

<System.STAThread()> _
Public Shared Sub Main()
'Allow only one instance of the monitor to be running
Dim appSingleton As New System.Threading.Mutex(False, "Single
Instance My Program")
If appSingleton.WaitOne(0, False) Then
'Enable Visual Styles if needed
If Environment.OSVersion.Platform = PlatformID.Win32NT _
AndAlso Environment.OSVersion.Version.Major >= 5 _
AndAlso Environment.OSVersion.Version.Minor > 0
Then
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
Application.EnableVisualStyles()
End If
Application.DoEvents()
End If
'Add any needed Handlers
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, New
Microsoft.Win32.SessionEndingEventHandler(AddressOf OnSessionEnding)
'Run the form
System.Windows.Forms.Application.Run(New frmMonitor)
End If
appSingleton.Close()
End Sub

I do a few things in mine. I allow only a single instance of the
application to run. That's what the mutex is for. I also enable the
use of themes for the versions of Windows that can support themes. And
I also add a handler for when the user ends a session (logs off, shuts
down, restarts). This handler is useful and prevents windows from
popping up that window saying that it's trying to shut down your
application but can't. This of course only happens if you have
something happening when your application exits, but it can be useful.
This is the function for that handler.

Private Shared Sub OnSessionEnding(ByVal sender As Object, ByVal e
As Microsoft.Win32.SessionEndingEventArgs)
Application.Exit()
End Sub

If you just want a simple main, then it really only requires a single
line of code.

<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New frmMonitor)
End Sub

Hope this helps you out.

Derek Woo
 
H

Herfried K. Wagner [MVP]

I have vb.net 1.0 book and wokring on vb.net 1.1 version
book says, there is Sub Main with attriubte STAThread in Form1, but I
don't see it in vs.net generated code and also
event handling for button click, book says, the form of delegate +=,
but vs.net using "Handles" keyword.


I assume your book is about C#, not VB.NET.
 
W

wooster11

Oops, I meant to say that 1.1 definitely does NOT generate the Sub
Main. Sorry about that.
 
C

Cor Ligthert [MVP]

Herfried,

I had to think in what relation do you did mean, however thinking a little
bit furter than there is maybe VBNet and C# discussed in this book.

I assume that you mean with the text beneath than,
I assume your book is about C#, not VB.NET.

I assume your books handles in that part probably C# not VB.Net

Good catch.

:)

Cor
 

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