Jump to content


Photo

Error when using multiple threads (c#)


  • Please log in to reply
6 replies to this topic

#1 tdrinkhill

tdrinkhill
  • Members
  • 4 posts

Posted 01 September 2005 - 01:19 PM

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

#2 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 01 September 2005 - 02:07 PM

Hmm ...

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

Thank you.
-Mat

#3 tdrinkhill

tdrinkhill
  • Members
  • 4 posts

Posted 01 September 2005 - 02:24 PM

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?

#4 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 01 September 2005 - 04:53 PM

Thanks a lot.

I think I've found the problem. Please install the new version:
http://www.smartftp..../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

#5 tdrinkhill

tdrinkhill
  • Members
  • 4 posts

Posted 02 September 2005 - 08:31 AM

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?

#6 tdrinkhill

tdrinkhill
  • Members
  • 4 posts

Posted 02 September 2005 - 09:39 AM

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.

#7 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 02 September 2005 - 01:00 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users