I am developing my first VB program. The program's main task is to send Skype messages using SendKeys.
I managed to send messages successfully but it is kinda slow as I need to use System.Threading.Thread.Sleep(1000)
to properly send messages. If I remove the Sleep(1000)
function, the program starts to do weird things like partial messages, some dialogs not showing up and at the end Skype crashed and I couldn't type anything.
Problem: How to remove Sleep(1000)
to send messages without such large pause? If I have more than 500 contacts it takes lot of time.
My code:
Dim all() As String = System.IO.File.ReadAllLines(appPath)
Dim message_text As String = TextBox1.Text
If all.Length > 0 Then
For i = 0 To all.Length - 1
System.Threading.Thread.Sleep(1000) '' < ---this line
Skype.Client.OpenMessageDialog(all(i))
Skype.Client.Focus()
SendKeys.SendWait(message_text + " - " + DateTime.Now.ToString())
SendKeys.SendWait("{ENTER}")
System.Threading.Thread.Sleep(100)
Next
MessageBox.Show("Ziņa nosūtīta Skype lietotājiem")
Else
End If
I don't understand why it sometimes sends just partial messages as I am using SendKeys.SendWait
that should wait till message text is copied in dialog and then Sending "Enter" key.