Handlers hang on vb.net 2005

I'm having some wierd issues with handlers working in vb.net 2005.

Not sure if I'm missing something here but I'm basing this off the sample and porting it over to use a form instead of command.

I start off using

[codebox]Public Class Form1
Public objFTP As FTPConnectionMTA
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objGlobal As sfFTPLib.[Global]
'objGlobal = CreateObject("sfFTPLib.Global")
objGlobal = New sfFTPLib.[Global]
objFTP = New sfFTPLib.FTPConnectionMTA
...licnence info here...
' Attach the event handler
AddHandler objFTP.OnConnect, AddressOf _OnConnect
AddHandler objFTP.OnChangeDirectory, AddressOf _OnChangeDirectory
AddHandler objFTP.OnTransferProgress, AddressOf _OnTransferProgress
for the handlers I do
[codebox] Private Sub _OnChangeDirectory(ByVal szDirectory As String)
TextBox2.Text = TextBox2.Text & "OnChangeDirectory(" & szDirectory & ")"
End Sub

Private Sub _OnTransferProgress(ByVal nBytesTransferredLo As Integer, ByVal nBytesTransferredHi As Integer)
TextBox2.Text = TextBox2.Text & "OnTransferProgress(" & objFTP.LastTransferBytes & ")"
End Sub

Private Sub _OnConnect()
TextBox2.Text = TextBox2.Text & "Connected"
End Sub[/codebox]

For some reason as soon as it tryed to write to TextBox2 or any other UI element it hangs.
I'm I missing something here?


Hello ...

UI elements always need to be updated in the main (UI) thread. There are two solutions:
1. Use the STA class (FTPConnectionSTA). Then all FTP events come from the main thread. I strongly recommended not to use the STA class.
2. Update the UI elements in the UI thread. I'm not sure how exactly this is done in vb.net but in C++ we send a message to the UI thread in the FTP event handlers. And the message handler in the UI thread then updates the UI controls.

I hope this helps.


I've tried everything from BackgroundWorkers to Invoke

I think Invoke is what I need to use but I'm not having any success

multitreading is very new to me and I'm stuck.

I trying to use [codebox]Delegate Sub ChangeTextControlDelegate(ByVal aTextBox As TextBox, ByVal newText As String)[/codebox]

[codebox]Private Sub _OnConnect()

If Me.TextBox2.InvokeRequired Then
Me.TextBox2.Invoke( _
New ChangeTextControlDelegate( _
AddressOf SetDisplayText), New Object() {TextBox2, "connected"})
Me.SetDisplayText(TextBox2, _
End If
End Sub

Public Sub SetDisplayText(ByVal aTextBox As TextBox, ByVal newText As String)
aTextBox.AppendText(newText & System.Environment.NewLine)
End Sub[/codebox]
I'm still having the same problem.
From what I read using the invoke and Delegate it's suppost to call the main thread that my ui components are on.

mb or anyone else have any suggestions?

mb could you give me a example on what you do in c++ and maybe I can convert it to vb.net

very right now with this

Thanks for the help

The problem is that you are calling the functions from the FTP component in your UI thread:
UI Thread:

This is wrong. You have to call the FTP functions from another thread.