locked
Simple Threading Problem? RRS feed

  • Question

  • Hey guys, I have a simple threading problem. Heres the code that causes the probem.

    The Code:

     

    Public Class Form1
        Public G As Player
        Dim P As New Test
       
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.CheckForIllegalCrossThreadCalls = False
            G = New Player
            P.H.Main()
        End Sub
        Public Function getplayer() As Integer
          
            Return G.Width
        End Function
    End Class
    
    
    Public Class SomeHandler
        Dim I As New Threading.Thread(AddressOf Handle)
    
        Public Sub Main()
    
            I.Start()
    
        End Sub
    
        Public Sub Handle()
    
            MsgBox(Form1.getplayer())
    
        End Sub
    End Class
    
    
    Public Class Player
        Public Width As Integer = 32
    
        Public Height As Integer = 32
    End Class
    

    The Error:  Object reference not set to an instance of an object.

     

    There are few things I cant dim as new so im sunk. Please Help! Thanks - Matt

     


    P.S. Please help guys I have spent days trying to fix that simple code. At one point I got it to work. But I had to call a funtion in the player class to set the width to 100 and the msgbox it and that worked. But thats not what I want. I want on load to do that and be able to in another thread msgbox that. But it just says 0. Please Help!!!! Thanks.
    • Edited by civilwarrock Thursday, November 10, 2011 7:19 AM
    Thursday, November 10, 2011 12:25 AM

Answers