Disconnect Event Firing before DataReceived event - WeOnlyDo Discussion board

Disconnect Event Firing before DataReceived event (General questions)

by scott, Thursday, August 05, 2004, 21:00 (7413 days ago)

I'm working on a class that needs to execute a program on a server over an ssh connection. The problem I'm having is that the Disconnected event fires before I receive the data in the DataReceived event. If I set breakpoints in the code I can see that the DataReceived event fires, I just can't get access to it since the Disconnected event has already returned me back from my class. I would use the DataReceived event to capture the data, but some of the commands require 2 or 3 receive events before all of the data is received.

The code that I'm using is:

Private WithEvents ssh as New ssh()

Public Sub RunCommand()

with ssh
.Hostname = host
.Login = login
.Password = password
.Command = command
.Protocol = SupportedProtocols.SSHAuto
.Encryption = EncryptionMethods.Auto
.Connect
End With

do
'Don't do anything i just want to give the thread time to complete
until ssh.State = States.Disconnected

End Sub
In the Receive event I set a module level variable to the results of the command then raise an even in the disconnect event that returns the result to the calling app.

Private Sub ssh_DataReceivedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.DataReceivedArgs) Handles ssh.DataReceivedEvent) handles ssh.DataReceivedEvent

dim s as string = ssh.receive()
m_Results &= s

End Sub

Private Sub ssh_DisconnectedEvent(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles ssh.DisconnectedEvent

RaiseEvent CommandComplete(m_Results, m_Command)
m_Results =

End Sub

Any help would be appreciated.


Complete thread: