Click here to Skip to main content

.NET Framework

 
Question[VB.NET 2008] Change form from separate thread (Windows CE) PinmemberMember 949661319-Nov-12 3:51 
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberSimon_Whale19-Nov-12 4:04 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661319-Nov-12 5:37 
AnswerRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen19-Nov-12 6:04 
Member 9496613 wrote:
Where did I go wrong?

Can anyone give me a tip?

Two; don't use global variables to pass state, and set MSDN[^] as your homepage. Try something similar to the code below;
Imports System.Threading
 
Public Class Form1
    Dim MyNewThread As Thread
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'create the thread 
        MyNewThread = New Thread(AddressOf MyThread.MyThreadExecute)
        MyNewThread.Name = "NuovoThread"
        'start the thread
        MyNewThread.Start(Me)
    End Sub
 
    Public Sub AggiornaLabel(ByVal What As String)
        If InvokeRequired Then
            Invoke(New Action(Of String)(AddressOf AggiornaLabel), New Object() {What})
            Return
        End If
 
        Label1.Text = What
    End Sub
End Class
 
Public Class MyThread
    Private Shared miii As Int32 = 0
 
    Public Shared Property iii() As Int32
        Get
            Return miii
        End Get
        Set(ByVal value As Int32)
            miii = value
        End Set
    End Property
 
    Public Shared Sub MyThreadExecute(ByVal Origin As Object)
        Dim OriginForm As Form1 = CType(Origin, Form1)
        Do
            iii = iii + 1
            OriginForm.AggiornaLabel(iii.ToString)
            Thread.Sleep(100)
        Loop
    End Sub
End Class
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661319-Nov-12 23:54 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 1:53 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 4:36 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 5:33 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 6:23 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen20-Nov-12 10:21 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) Pinmembersteve_949661320-Nov-12 22:25 
GeneralRe: [VB.NET 2008] Change form from separate thread (Windows CE) PinmemberEddy Vluggen21-Nov-12 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 1 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid