Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2004, 10:54 AM
Authorized User
 
Join Date: Oct 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use of <STAThread()>

In the code below taken from an example on MSDN. I noticed the use of <STAThread()> on the Sub Main statement.

Pressing F1 gave me an explanation which gave me little.

Anyone know the purpose of this addition?




'//------------------------------------------------------------------------------
'/// <copyright from='1997' to='2001' company='Microsoft Corporation'>
'/// Copyright (c) Microsoft Corporation. All Rights Reserved.
'///
'/// This source code is intended only as a supplement to Microsoft
'/// Development Tools and/or on-line documentation. See these other
'/// materials for detailed information regarding Microsoft code samples.
'///
'/// </copyright>
'//------------------------------------------------------------------------------
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Namespace Microsoft.Samples.WinForms.VB.Accessible

    Public Class Accessible
        Inherits System.Windows.Forms.Form

        'The main entry point for the application
        <STAThread()> Shared Sub Main()
            Application.Run(New Accessible)
        End Sub

        Public Sub New()
            MyBase.New()

            Accessible = Me

            'This call is required by the Windows Forms Designer.
            InitializeComponent()

            'Set the minimum form size to the client size + the height of the title bar
            Me.MinimumSize = New Size(392, (117 + SystemInformation.CaptionHeight))

        End Sub

        'Form overrides dispose to clean up the component list.

        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region " Windows Form Designer generated code "

        'Required by the Windows Forms Designer
        Private components As System.ComponentModel.Container
        Private WithEvents button1 As System.Windows.Forms.Button
        Private WithEvents textBox1 As System.Windows.Forms.TextBox

        Private WithEvents Accessible As System.Windows.Forms.Form

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.
        'Do not modify it using the code editor.
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Me.button1 = New System.Windows.Forms.Button
            Me.textBox1 = New System.Windows.Forms.TextBox

            Me.Text = "Accessibility"
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.AccessibleRole = System.Windows.Forms.AccessibleRole.Window
            Me.AccessibleName = "AccessibleForm"
            Me.AcceptButton = button1
            Me.AccessibleDescription = "Simple Form that demonstrates accessibility"
            Me.ClientSize = New System.Drawing.Size(392, 117)

            button1.AccessibleDescription = "Once you've entered some text push this button"
            button1.Size = New System.Drawing.Size(120, 40)
            button1.TabIndex = 1
            button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            button1.Location = New System.Drawing.Point(248, 64)
            button1.Text = "Click Me!"
            button1.AccessibleName = "DefaultAction"

            textBox1.Location = New System.Drawing.Point(16, 24)
            textBox1.Text = "Hello WinForms World"
            textBox1.AccessibleName = "TextEntryField"
            textBox1.TabIndex = 0
            textBox1.AccessibleDescription = "Please enter some text in the box"
            textBox1.Anchor = CType(15, System.Windows.Forms.AnchorStyles)
            textBox1.Size = New System.Drawing.Size(360, 20)

            Me.Controls.Add(textBox1)
            Me.Controls.Add(button1)
        End Sub

#End Region

        Protected Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            MessageBox.Show("Text is: '" + textBox1.Text + "'")
        End Sub

    End Class

End Namespace
 
Old October 10th, 2004, 12:32 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

STAThread says that the application is a Single Threaded Apartment. In short it says that the components live in a single thread no other thread calls the component in another thread.

Try the following Link for more information.

http://msdn.microsoft.com/library/en...nthrd_68s3.asp
http://msdn.microsoft.com/library/en...nthrd_8po3.asp
http://support.microsoft.com/default...b;en-us;318402



It is not how much we do,
but how much love we put in the doing.

-Mother Theresa
 
Old October 18th, 2004, 06:30 AM
Authorized User
 
Join Date: Oct 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your answer. It now makes a little more sense.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<STAThread()> _ ? sumsin VS.NET 2002/2003 1 March 24th, 2005 05:58 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 05:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.