Click here to Skip to main content
15,917,618 members

Comments by ftpx (Top 4 by date)

ftpx 17-Nov-23 1:25am View    
Thank you, Dave. I think I'll break my drag and drop habit and stick with the (ctrl+F9) key combination.
ftpx 16-Nov-23 10:28am View    
First of all, thank you very much for your support effort. Since 15 years I have been actively writing code. The problem is not only in this sample code but in all our projects. This problem has been present since Visual Studio 2022 was first released. That's why we still continue to use VS2019 as a team. Because we do not experience this problem.

I have attached a video to my question to explain the difference between VS2022 and VS2019. You can check that too.

I shortened the code for you, please watch the video on this link.

Problem Video
ftpx 16-Nov-23 5:35am View    
I think I didn't fully explain my problem. I did a clean install on a virtual machine and took a screen recording. Please watch the video in the link.

SS Video
ftpx 16-Nov-23 1:00am View    
Yes, tested with a clean installed windows and visual studio with no plugins. Even tested on different computers. By the way, the code doesn't matter. I have created many sample projects. If you open the same code with VS2019 there is no problem. I can set the line I want the code to continue by dragging and dropping with the mouse. I have been doing this for years :)

I am attaching a sample code. Put a breakpoint on the first line of the PingProccess method and try changing the line in the same method. It will block you with a red forbidden sign. Add a few empty lines after the line. Now you can go to that line. But there seems to be no fixed logic.

Note: If I write the same code exactly in C#, there is no problem.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim p As New Pinger
        p.Start("192.168.1.1254")
    End Sub
End Class

Class Pinger
    Private who_ As String

    Private pingSender_ As Ping
    Public Event ReturnValue(value As String)

    Private cancel_ As Boolean = False

    Sub New()
        pingSender_ = New Ping
        AddHandler pingSender_.PingCompleted, AddressOf pingSender__PingCompleted
    End Sub

    Public Sub Cancel()
        cancel_ = True
        pingSender_.SendAsyncCancel()
    End Sub

    Public Sub Start(who As String)
        who_ = who
        RaiseEvent ReturnValue("Starting")
        PingProccess()
    End Sub

    Private Sub PingProccess()
        If cancel_ Then Exit Sub
        Dim waiter_ As New AutoResetEvent(False)

        Thread.Sleep(1000)
        Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        Dim buffer() As Byte = Encoding.ASCII.GetBytes(data)
        Dim timeout As Integer = 1000
        Dim options As New PingOptions(64, True)
        pingSender_.SendAsync(who_, timeout, buffer, options, waiter_)
        If cancel_ Then Exit Sub
        Application.DoEvents()

    End Sub

    Private Sub pingSender__PingCompleted(sender As Object, e As PingCompletedEventArgs)

        If e.Cancelled Then
            RaiseEvent ReturnValue("Ping cancel")
            CType(e.UserState, AutoResetEvent).Set()
        End If

        If Not IsNothing(e.Error) Then
            RaiseEvent ReturnValue("Ping error : ")
            RaiseEvent ReturnValue(e.Error.ToString)
            CType(e.UserState, AutoResetEvent).Set()
        End If

        Dim reply As PingReply = e.Reply
        DisplayReply(reply)

        CType(e.UserState, AutoResetEvent).Set()

        PingProccess()

    End Sub



    Private Sub DisplayReply(reply As PingReply)
        If IsNothing(reply) Then

        ElseIf reply.Status = IPStatus.Success Then
            RaiseEvent ReturnValue("Reply from " & reply.Address.ToString & ": bytes= " & reply.Buffer.Length & " time =  " & reply.RoundtripTime & "ms TTL=" & reply.Options.Ttl)
        End If
    End Sub
End Class