Calling a class locks the player until done.

Im probably doing something thats obviously wrong, but I dont know which class to make the changes in.

I call a coroutine:
ReadXMLClass.cs

void Awake () {
	StartCoroutine("fncGetXMLData");
}

the IEnum function reads in some XML and then inits a download:
ReadXMLClass.cs

	IEnumerator fncGetXMLData(){
//Init XML read
	
	//Read XML Code...

	//Begin File Download
    	FTPManager ftplib = new FTPManager();
		ftplib.Connect("ftp.ftp.com",21,"username","password");



		while(ftplib.DoDownload() > 0)

		{

			int perc = (int)(((ftplib.BytesTotal) * 100) / ftplib.FileSize);

			string strProgress;
			strProgress = string.Format("\rDownloading: {0}/{1} {2}%", ftplib.BytesTotal, ftplib.FileSize, perc); 
			Debug.Log(strProgress);

		}
    }

I have another large script which is an FTP manager that i use to connect and download stuff into Unity - problem is, whenever i connect or download, the engine is frozen until the request completes:
FTPManager.cs

//Connect function example...
		public int Connect()

		{

			if (server == null)

				throw new Exception("No server has been set.");

			if (user == null)

				throw new Exception("No username has been set.");



			if (main_sock != null)

				if (main_sock.Connected)

					return -1;



			main_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

			main_ipEndPoint = new IPEndPoint(Dns.GetHostByName(server).AddressList[0], port);

			

			try

			{

				main_sock.Connect(main_ipEndPoint);	

			}

			catch(Exception ex)

			{

				throw new Exception(ex.Message);

			}



			ReadResponse();

			if (response != 220)

				Fail();



			SendCommand("USER " + user);

			ReadResponse();



			switch(response)

			{

				case 331:

					if (pass == null)

					{

						Disconnect();

						throw new Exception("No password has been set.");

					}

					SendCommand("PASS " + pass);

					ReadResponse();

					if (response != 230)

						Fail();

					break;

				case 230:

					break;

			}

			

			return 	1;

		}

I initially thought yield could be an answer, but I dont have control over .NET FTP function after I call it. I thought invoking a new thread could work, but I’m not 100% sure about how that works with Unity - which is why im posting :wink:

Also - Reading the XML works fine (no lock while requesting data), as I’m using the built-in WWW in Unity- but Im assuming other .Net components are not aware of of Unity and thus lock until complete.

Cheers
Shaun

bump! - really need some help with this :wink:

Im guessing its a Threading issue?

Thanks!

Shaun

Coroutines aren’t thread-based, so that’s probably the reason for the hang.

I’m not sure of a way to spawn a background process like this for any .NET function call that will wait before returning. OTEE or someone more experienced can hopefully help…

Hi

This thread started long time ago, but I’d like to know if anyone could find a solution?
I’m having exactly the same problem: when I use ftplib to get some files from a server, player is blocked until it finishes.
I’m using ftplib because iPhone version of Unity only accepts .NET 1.1 so I can’t use .NET functions for ftp.