Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.2k views
in .NET FTP by (440 points)
I'm using the edtftp control in a small FTP application made in VB 2005. I've been working on it for a couple of weeks and everything was ok. The last few days I have been tweaking the GUI, and I've added an option to start minimized. The weird thing is, when I start the program minimized and it starts to transfer the file specified in the commandline, I get an error. When I run it with Me.Windowstate = FormWindowState.Normal the transfer works fine. When I start the program normally, and I minimize it between the FTP connect and transfer, it also gives the error. If I minimize the form AFTER the transfer has started, it works fine

This is the error I'm getting
Exception has been thrown by the target of an invocation.

            If FtpC.IsConnected = True Then
                Try
                    StatusLabel.Text = "Uploading file: " & DestinationFile
                    FtpC.UploadFile(s, DestinationFile)
                Catch ex As System.Exception
                    Console.WriteLine("Error during transfer" & vbCrLf & ex.Message)
                    MessageBox.Show("Error during transfer" & vbCrLf & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Exiting = True
                    Application.Exit()
                    End
                End Try
            End If

So, the above code runs fine when the form is in its normal state, but it throws an exception when minimized.

14 Answers

0 votes
by (161k points)
Now that's a weird error. Minimizing is changing the behaviour, but I don't have any idea why. If you find an answer, please follow up.
0 votes
by (440 points)
Now that's a weird error. Minimizing is changing the behaviour, but I don't have any idea why. If you find an answer, please follow up.

I will, but I'm not very hopeful. The weird thing is, that the .Connect part of the control works fine minimized, but he .UploadFile doesn't. I don't really know how your control is designed, so I have no idea why this is.

Are you guys able to reproduce it?
0 votes
by (51.2k points)
Would you be able to e-mail a test program to support@...? If we can reproduce it then it should be quite easy to fix it. If that's not possible then please post a stack-trace and/or a log.

- Hans (EDT)
0 votes
by (440 points)
My apologies, it seems I'm wrong. It isn't the minimized state that is causing the exception, but the fact that I'm hiding the form.
When the user minimizes the form, it minimizes to the system tray.
    Private Sub Transfer_Window_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
            Small_Status.Show()
            Me.WindowState = vbNormal
            NotifyIcon1.Visible = True
        End If
    End Sub

It's the 'Me.Hide()' that is causing the exception. The exception is also thrown on 'Me.Visible=False' and 'Me.ShowInTaskbar=False'
Is there any way around this? Because I really want to be able to minimize to the systemtray

Just to be clear, the exception is only thrown if I hide the form before the file transfer start. If I hide it when the file is already transferring everything is ok.
0 votes
by (161k points)
Enable logging and post a snippet that shows the upload:

Imports EnterpriseDT.Util.Debug;

ftpConn.LogLevel = LogLevel.All;
ftpConn.LogFile = "mylogfilename";

It might also be worth trying:

ftpConn.UseGuiThreadIfAvailable = false;
0 votes
by (440 points)
Enable logging and post a snippet that shows the upload:

Imports EnterpriseDT.Util.Debug;

ftpConn.LogLevel = LogLevel.All;
ftpConn.LogFile = "mylogfilename";

It might also be worth trying:

ftpConn.UseGuiThreadIfAvailable = false;


Here's the problem
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.654 : Invoking delegate EnterpriseDT.Net.Ftp.BytesTransferredHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.654 : Finding MainWindowHandle
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.654 : No MainWindowHandle found
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.654 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.654 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.701 : Invoking delegate EnterpriseDT.Net.Ftp.BytesTransferredHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.701 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 14:31:11.701 : Invoking delegate dynamically

So the control can't find the MainWindowHandle because I hid it (Me.Hide()).
But doesn't the .Hide command only hide it visually? I mean, it's still loaded and in memory, right?
0 votes
by (161k points)
The issue seems to be that when the window is hidden, something goes wrong with event handling.

Can you try setting

EventsEnabled = false

and let us know what happens.
0 votes
by (440 points)
Strange I've set FtpC.EventsEnabled = False but it still tries to trigger BytesTransferred
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 27 okt 2006 16:51:13.957 : 150 Accepted data connection
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:13.973 : Invoking delegate EnterpriseDT.Net.Ftp.BytesTransferredHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:13.973 : Finding MainWindowHandle
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:13.973 : No MainWindowHandle found
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:13.973 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:13.973 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:14.020 : Invoking delegate EnterpriseDT.Net.Ftp.BytesTransferredHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:14.020 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 27 okt 2006 16:51:14.020 : Invoking delegate dynamically
0 votes
by (161k points)
Ok. It is probably best at this point if you can write a little test program that illustrates the problem. Email it to us and we should be able to figure out the problem. Also let us know what version of the FTP client you are using.
0 votes
by (440 points)
Ok. It is probably best at this point if you can write a little test program that illustrates the problem. Email it to us and we should be able to figure out the problem. Also let us know what version of the FTP client you are using.

I've written a program that reproduces the problem and mailed it along with the sourcecode to support@enterprisedt.com

Categories

...