Click here to Skip to main content
15,912,069 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: call a Sub with a dynamic type parameter. Pin
Richard MacCutchan3-Jan-19 6:33
mveRichard MacCutchan3-Jan-19 6:33 
GeneralRe: call a Sub with a dynamic type parameter. Pin
Dave Kreskowiak3-Jan-19 6:36
mveDave Kreskowiak3-Jan-19 6:36 
AnswerRe: call a Sub with a dynamic type parameter. Pin
Eddy Vluggen2-Jan-19 22:14
professionalEddy Vluggen2-Jan-19 22:14 
GeneralRe: call a Sub with a dynamic type parameter. Pin
desanti3-Jan-19 4:35
desanti3-Jan-19 4:35 
GeneralRe: call a Sub with a dynamic type parameter. Pin
Ralf Meier17-Jan-19 0:34
mveRalf Meier17-Jan-19 0:34 
QuestionDirecotoryServices - Find all Windows 7 and Windows 10 Computers in Domain Pin
Member 1186689325-Dec-18 6:43
Member 1186689325-Dec-18 6:43 
AnswerRe: DirecotoryServices - Find all Windows 7 and Windows 10 Computers in Domain Pin
Eddy Vluggen2-Jan-19 23:02
professionalEddy Vluggen2-Jan-19 23:02 
QuestionThreading, Invoke, Delegate and MethodInvoker... Pin
Member 1111281423-Dec-18 3:03
Member 1111281423-Dec-18 3:03 
Learning Threading, Invoke, Delegate and MethodInvoker ...

0) I use Visual Basic 2017.
1) I can press Button1 or Button2 randomly: works!
2) After the first round I can only press Button2. Button1 no longer works!
3) Who can indicate IN THE CODE where the error is?
4) I search for information everywhere on the internet, but what exactly Invoke, Delegate and MethodInvoker do, is not completely clear to me … Sigh | :sigh:

5) Thank you …

VB
Public Class Form1

    Dim Number1 As Integer
    Dim Number2 As Integer

    Dim Thread1 As System.Threading.Thread
    Dim Thread2 As System.Threading.Thread

    Private Delegate Sub UpdateLabel1Delegate(ByVal Number1 As Integer)
    Private Delegate Sub UpdateLabel2Delegate(ByVal Number2 As Integer)

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Thread1 = New System.Threading.Thread(AddressOf CountUp)
        Thread1.Start()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Thread2 = New System.Threading.Thread(AddressOf CountDown)
        Thread2.Start()
    End Sub

    Private Sub CountUp()
        Do Until Number1 = 1000
            Number1 = Number1 + 1
            UpdateLabel1Text(Number1)
        Loop
    End Sub 'CountUp

    Private Sub CountDown()
        Number2 = 1000
        Do Until Number2 = 0
            Number2 = Number2 - 1
            UpdateLabel2Text(Number2)
        Loop
    End Sub 'CountDown

    Private Sub UpdateLabel1Text(ByVal Number1 As Integer)
        If Label1.InvokeRequired Then
            ' This is a cross-thread call, so
            ' invoke a call back to this method.
            Me.BeginInvoke(New UpdateLabel1Delegate(AddressOf UpdateLabel1Text), Number1)
        Else
            ' We're being called on the UI thread, so just update the label.
            Label1.Text = Number1
            Me.Refresh()
        End If
    End Sub

    Private Sub UpdateLabel2Text(ByVal Number2 As Integer)
        If Label2.InvokeRequired Then
            ' This is a cross-thread call, so
            ' invoke a call back to this method.
            Me.BeginInvoke(New UpdateLabel2Delegate(AddressOf UpdateLabel2Text), Number2)
        Else
            ' We're being called on the UI thread, so just update the label.
            Label2.Text = Number2
            Me.Refresh()
        End If
    End Sub

End Class

AnswerRe: Threading, Invoke, Delegate and MethodInvoker... Pin
Eddy Vluggen23-Dec-18 10:52
professionalEddy Vluggen23-Dec-18 10:52 
GeneralRe: Threading, Invoke, Delegate and MethodInvoker... Pin
Member 1111281423-Dec-18 11:09
Member 1111281423-Dec-18 11:09 
GeneralRe: Threading, Invoke, Delegate and MethodInvoker... Pin
Eddy Vluggen23-Dec-18 11:14
professionalEddy Vluggen23-Dec-18 11:14 
QuestionVB Client server with timer Pin
Member 1409761321-Dec-18 21:49
Member 1409761321-Dec-18 21:49 
AnswerRe: VB Client server with timer Pin
Richard MacCutchan21-Dec-18 22:00
mveRichard MacCutchan21-Dec-18 22:00 
GeneralRe: VB Client server with timer Pin
Member 1409761321-Dec-18 22:16
Member 1409761321-Dec-18 22:16 
AnswerRe: VB Client server with timer Pin
Dave Kreskowiak22-Dec-18 4:12
mveDave Kreskowiak22-Dec-18 4:12 
QuestionHow to get a list of installed applications and uninstall them ? Pin
Lucifer Morningstar19-Dec-18 22:59
Lucifer Morningstar19-Dec-18 22:59 
SuggestionRe: How to get a list of installed applications and uninstall them ? Pin
CHill6019-Dec-18 23:07
mveCHill6019-Dec-18 23:07 
AnswerRe: How to get a list of installed applications and uninstall them ? Pin
Richard MacCutchan19-Dec-18 23:22
mveRichard MacCutchan19-Dec-18 23:22 
AnswerRe: How to get a list of installed applications and uninstall them ? Pin
Eddy Vluggen20-Dec-18 0:39
professionalEddy Vluggen20-Dec-18 0:39 
QuestionTrying to create a search query that will bring the results searched in access database. It is bringing up an error runtime error '3075' Pin
Member 1409033914-Dec-18 22:07
Member 1409033914-Dec-18 22:07 
AnswerRe: Trying to create a search query that will bring the results searched in access database. It is bringing up an error runtime error '3075' Pin
Richard MacCutchan14-Dec-18 22:51
mveRichard MacCutchan14-Dec-18 22:51 
GeneralRe: Trying to create a search query that will bring the results searched in access database. It is bringing up an error runtime error '3075' Pin
Member 1409033915-Dec-18 5:22
Member 1409033915-Dec-18 5:22 
AnswerRe: Trying to create a search query that will bring the results searched in access database. It is bringing up an error runtime error '3075' Pin
Dave Kreskowiak15-Dec-18 5:16
mveDave Kreskowiak15-Dec-18 5:16 
QuestionHow to assign enter key? Pin
Member 1408751912-Dec-18 20:07
Member 1408751912-Dec-18 20:07 
AnswerRe: How to assign enter key? Pin
Richard MacCutchan12-Dec-18 22:00
mveRichard MacCutchan12-Dec-18 22:00 

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.