Share Pastebin
Guest
Public paste!

ninlar

By: a guest | Jan 25th, 2009 | Syntax: VB.NET | Size: 0.70 KB | Hits: 906 | Expires: Never
Copy text to clipboard
  1. Imports System.Threading
  2.  
  3. Public Class Form1
  4.  
  5.     Private Delegate Sub NoParams()
  6.  
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.         Dim tThread As New Thread(New ParameterizedThreadStart(AddressOf ListenThread))
  10.  
  11.         tThread.Start(Me)
  12.  
  13.     End Sub
  14.  
  15.     Private Sub ListenThread(ByVal frmMain As Object)
  16.         Dim dlgMain As Form = Nothing
  17.  
  18.         dlgMain = CType(frmMain, Form)
  19.  
  20.         Thread.Sleep(2000)
  21.         dlgMain.Invoke(New NoParams(AddressOf ShowMsgBox))
  22.  
  23.  
  24.  
  25.     End Sub
  26.  
  27.     Private Sub ShowMsgBox()
  28.         MessageBox.Show("This is a messagebox that was created from a thread")
  29.     End Sub
  30. End Class