Results 1 to 2 of 2

Thread: Interesting chunk of code I wrote

  1. #1

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Interesting chunk of code I wrote

    you may or may not find this usefull, but it at least shows multithreading...but run this and type something into the console window and hit enter and the forms Caption will change. This shows how you can run a sub in the bakground listening for something to happen while the program can still function normally.

    Code:
    REM created on 03/26/2002 at 11:40 AM
    Imports System
    Imports System.Windows.Forms
    Imports Microsoft.VisualBasic
    Imports System.Threading
    
    
    Module MainApp
    		Sub Main(ByVal args() As String)
    			Application.Run(New MainForm)
    		End Sub
    End Module
    
    Class MainForm
    	Inherits Form
    	Private WithEvents btnOne As Button
    	Private myButt As Button
    	Private myThread As Thread
    	
    	Public Sub New()
    		' Form constructor
    		
    		btnOne = New Button
    		btnOne.Name = "myButt"
    		myButt = btnOne
    		
    		myButt.Text = "Click Me"
    		Me.Controls.Add(myButt)
    		Console.Writeline("Enter a name for the form")
    		Me.Text = "Test"
    		myThread = New Thread(AddressOf ListenToConsole)
    		myThread.Start()
    	End Sub
    	
    	Public Sub ListenToConsole()
    		Do
    			Me.Text = Console.Readline()
    		Loop Until False
    	End Sub
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    REM?
    Please rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width