-2

I've been trying some things to achieve the desired, but without good results since I'm not very knowledgeable with this language. I wish the "function" c.SendMessagese send with a delay of X seconds. I hope you can help me with this, as I continue investigating. Thank you for your help.

Example

send delay 5sec c.SendMessage("Esto no es un comando1")
send delay 8sec c.SendMessage("Esto no es un comando2")
send delay 11sec c.SendMessage("Esto no es un comando3")
send delay 14sec c.SendMessage("Esto no es un comando4")

I hope I understood

My Code

    Private Sub oSkype_MessageStatus(pMessage As ChatMessage, Status As TChatMessageStatus) Handles oSkype.MessageStatus
    If Status = TChatMessageStatus.cmsReceived Or Status = TChatMessageStatus.cmsSent Then
        Dim msg As String = pMessage.Body
        Dim c As Chat = pMessage.Chat

        If msg.StartsWith(Trigger) Then
            LstBox.Items.Add(DateTime.Now.ToLongTimeString() + ":" + "command " + "'" + msg + "'" + "form " + pMessage.Sender.Handle)
            msg = msg.Remove(0, 1).ToLower
            c.SendMessage("Esto no es un comando1")
            c.SendMessage("Esto no es un comando2")
            c.SendMessage("Esto no es un comando3")
            c.SendMessage("Esto no es un comando4")
        End If
    End If
End Sub
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

1 Answers1

0

You could use the System.Threading.Thread.Sleep method to pause the execution of the current thread for "X" amount of time.

An example that sleeps during 3 seconds between each order:

Imports System.Threading

Console.WriteLine("1")
Thread.Sleep(TimeSpan.FromSeconds(3))

Console.WriteLine("2")
Thread.Sleep(TimeSpan.FromSeconds(3))

Console.WriteLine("3")
Thread.Sleep(TimeSpan.FromSeconds(3))

It will be better if you use asynchronous methodologies to avoid freezing the UI thread:

Imports System.Threading
Imports System.Threading.Tasks

Dim t As New task(
    Sub()
        Console.WriteLine("1")
        Thread.Sleep(TimeSpan.FromSeconds(3))

        Console.WriteLine("2")
        Thread.Sleep(TimeSpan.FromSeconds(3))

        Console.WriteLine("3")
        Thread.Sleep(TimeSpan.FromSeconds(3))
    End Sub)

t.Start()

Just as a suggestion not related to the question, please avoid using the + operator to concatenate strings, as I explained here.

Community
  • 1
  • 1
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417