Click here to Skip to main content
15,887,485 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Capture a monochrome image of panel control Pin
gwittlock3-May-14 3:41
gwittlock3-May-14 3:41 
GeneralRe: Capture a monochrome image of panel control Pin
Richard MacCutchan3-May-14 3:50
mveRichard MacCutchan3-May-14 3:50 
GeneralRe: Capture a monochrome image of panel control Pin
gwittlock3-May-14 5:09
gwittlock3-May-14 5:09 
GeneralRe: Capture a monochrome image of panel control Pin
Eddy Vluggen3-May-14 7:41
professionalEddy Vluggen3-May-14 7:41 
GeneralRe: Capture a monochrome image of panel control Pin
gwittlock3-May-14 7:53
gwittlock3-May-14 7:53 
Questionsimple multi thread app behaving weirdly Pin
Tony Snowden1-May-14 23:55
Tony Snowden1-May-14 23:55 
AnswerRe: simple multi thread app behaving weirdly Pin
Dave Kreskowiak2-May-14 5:31
mveDave Kreskowiak2-May-14 5:31 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden5-May-14 21:42
Tony Snowden5-May-14 21:42 
hi dave... I didn't know if posting the code straight up was the done thing.. thought I would see if anyone would take a look first.

thanks & heres the code -

VB
Imports System.IO
Imports System.Threading

Public Class Form1

    Dim i1 As Integer
    Dim i2 As Integer


    Private Sub count1()

        Do While i1 < 3000
            i1 += 1
            If Me.Label1.InvokeRequired Then
                Me.Label1.Invoke(New Action(Sub() Me.Label1.Text = i1))
                Me.Label1.Invoke(New Action(Sub() Me.Refresh()))
            Else
                Me.Label1.Text = i1
                Me.Refresh()
            End If
        Loop

    End Sub


    Private Sub count2()

        Do While i2 < 3000
            i2 += 1
            If Me.Label2.InvokeRequired Then
                Me.Label2.Invoke(New Action(Sub() Me.Label2.Text = i2))
                Me.Label2.Invoke(New Action(Sub() Me.Refresh()))
            Else
                Me.Label2.Text = i2
                Me.Refresh()
            End If
        Loop

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        i1 = 0
        Dim t As New Thread(AddressOf count1)
        t.Start()

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        i2 = 0
        Dim t2 As New Thread(AddressOf count2)
        t2.Start()

    End Sub


End Class





@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

EDIT -

Hi Dave.. After looking at some explanations of using delegates and invoke I have changed my code as follows.. Still doesn't work like I would expect! Frown | :(

VB
Imports System.IO
Imports System.Threading

Public Class Form1

    Dim i1 As Integer
    Dim i2 As Integer


    Private Delegate Sub SetCount1()
    Private Delegate Sub SetCount2()


    Private Sub count1()

        Do While i1 < 100000
            i1 += 1
            updatecount1()
        Loop

    End Sub


    Private Sub count2()

        Do While i2 < 100000
            i2 += 1
            updatecount2()
        Loop

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        i1 = 0
        Dim t As New Thread(AddressOf count1)
        t.Start()

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        i2 = 0
        Dim t2 As New Thread(AddressOf count2)
        t2.Start()

    End Sub


    Private Sub updatecount1()

        If Me.Label1.InvokeRequired Then
            Me.Label1.Invoke(New SetCount1(AddressOf updatecount1))
        Else
            Me.Label1.Text = i1
            Me.Refresh()
        End If


    End Sub


    Private Sub updatecount2()

        If Me.Label2.InvokeRequired Then
            Me.Label2.Invoke(New SetCount2(AddressOf updatecount2))
        Else
            Me.Label2.Text = i2
            Me.Refresh()
        End If

    End Sub

End Class


modified 6-May-14 9:57am.

GeneralRe: simple multi thread app behaving weirdly Pin
Dave Kreskowiak6-May-14 4:01
mveDave Kreskowiak6-May-14 4:01 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden6-May-14 4:31
Tony Snowden6-May-14 4:31 
GeneralRe: simple multi thread app behaving weirdly Pin
Dave Kreskowiak6-May-14 4:52
mveDave Kreskowiak6-May-14 4:52 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden6-May-14 22:05
Tony Snowden6-May-14 22:05 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden7-May-14 4:31
Tony Snowden7-May-14 4:31 
GeneralRe: simple multi thread app behaving weirdly Pin
Dave Kreskowiak7-May-14 6:07
mveDave Kreskowiak7-May-14 6:07 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden7-May-14 21:37
Tony Snowden7-May-14 21:37 
QuestionCombobox value not showed in the datagridview Pin
D.Manivelan1-May-14 23:33
D.Manivelan1-May-14 23:33 
SuggestionRe: Combobox value not showed in the datagridview Pin
Maciej Los2-May-14 8:55
mveMaciej Los2-May-14 8:55 
QuestionSubject message not passing to outlook window from VB6.0 Pin
kk20141-May-14 3:53
kk20141-May-14 3:53 
AnswerRe: Subject message not passing to outlook window from VB6.0 Pin
Dave Kreskowiak1-May-14 5:23
mveDave Kreskowiak1-May-14 5:23 
QuestionNeed help on "Competition Scheduling" Algorithm Pin
N.Wang30-Apr-14 16:43
professionalN.Wang30-Apr-14 16:43 
QuestionTwitter REST API V1.1 Pin
Pete_12328-Apr-14 8:10
Pete_12328-Apr-14 8:10 
AnswerRe: Twitter REST API V1.1 Pin
Richard Deeming28-Apr-14 8:27
mveRichard Deeming28-Apr-14 8:27 
GeneralRe: Twitter REST API V1.1 Pin
Pete_12328-Apr-14 9:20
Pete_12328-Apr-14 9:20 
AnswerRe: Twitter REST API V1.1 Pin
HenryHugo28-Apr-14 21:38
professionalHenryHugo28-Apr-14 21:38 
QuestionVB.Net - Best practice to store paths as relative path Pin
Bart Van Eyndhoven27-Apr-14 23:42
Bart Van Eyndhoven27-Apr-14 23:42 

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

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