Error when using multiple threads (c#)

I'm trying to create a .NET windows application (console library) that uses the SmartFTP .NET interop.

When I call the FTP code from within a new thread, the application seems to hang on the line that instantiates the FTPConnectionMTA object.

When I run the code from the main thread, everything works fine.

Any idea what's going on and how to fix this?

Thanks,


Tim

Hmm ...

Can you provide a small example project which shows the problem?

Thank you.
-Mat

Sure....








using System;



using System.Threading;



using sfFTPLib;







namespace FTPExample



{



    class Program



    {



        static void Main(string[] args)



        {







            //create a new thread



            Thread ftpThread = new Thread(new ThreadStart(CheckFTPSite));



            ftpThread.Name = "ftp_check";



            ftpThread.TrySetApartmentState(ApartmentState.MTA);



            ftpThread.Start();







            Console.WriteLine("Press 'q' to quit.");



            while (Console.Read() != 'q');



        }







        private static void CheckFTPSite()



        {



            FTPLib objFTP = new FTPLib("ftp.test.com", "test", "test", 21);



        }



    }







    class FTPLib



    {



        public FTPLib(string url, string username, string password, int port)



        {







            FTPConnectionMTA _ftp = new FTPConnectionMTA(); //the application will hang after this line.







            // host settings



            _ftp.Host = url;



            _ftp.Port = port;



            _ftp.Username = username;



            _ftp.Password = password;



            _ftp.Passive = true;







            // proxy settings



            _ftp.ProxyType = sfFTPLib.enumProxyType.ftpProxyTypeNone;



            _ftp.FTPProxyType = sfFTPLib.enumFTPProxyType.ftpFTPProxyTypeNone;







            // set CLNT name



            _ftp.Client = "test app";



            // log everything 



            _ftp.LogFile = "WorkingProgressSFM.log";











        }



    }



}








Just create a new console app and paste in... Any ideas?

Thanks a lot.

I think I've found the problem. Please install the new version:
https://www.smartftp.com/get/SFTPFTPLib.exe

It would be safer to delete the sfFTPLib.dll first before you run the setup above. The new dll version is 1.5.5.3.

Regards,
-Mat

Hi, Mat...

Thanks for the prompt reply - I've tried the new dll and am still getting the same error. One strange thing is that the version in visual studio still displays as 1.5.0.0, even though it's 1.5.5.3 in windows explorer.

Did it actually work when you tried the new dll with my code?

Another update - I've tried the example code on another developer's pc, and it worked - could this be a hardware thing?

My development pc is a 64bit Xeon (although I have 32bit Windows XP installed), with Hyperthreading enabled. The other pc i tried it on was a much worse specification - just a Celeron 2.66 (no HT, 32Bit etc).

Could that have made a difference? I've tried disabling HT, but this doesn't make a difference.

Hello ..

I changed the following line in your code:
ftpThread.ApartmentState = ApartmentState.MTA;

and it worked without a problem. I don't know where to go from here. I can send you a debug build which will display the asserts in case there are any of them.

Please contact me through PM/Email.

Regards,
-Mat