Jump to content


Photo

Application crash wen i used LastTransferSpeed in OnTransferProgress Event


  • Please log in to reply
2 replies to this topic

#1 Raimund

Raimund
  • Members
  • 14 posts

Posted 12 May 2006 - 11:59 PM

Hi,

I'm trying to create a C# .NET windows application that uses the SmartFTP .NET interop.

This sample works:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace FTPExample
{
	public class FTPLib
	{
		MainForm m_Form;

		sfFTPLib.FTPConnectionMTAClass _ftp;

		private void OnTransferProgress(int nTransferBytesLo, int nTransferBytesHi)
		{
			Int64 nTransferBytes = (uint)nTransferBytesLo;
			nTransferBytes <<= 32;
			nTransferBytes += (uint)nTransferBytesHi;
			m_Form.label1.BeginInvoke(m_Form.m_DelegateShowTransferProgress, new Object[] { nTransferBytes.ToString() });
		}

		public FTPLib(string url, string username, string password, int port, MainForm form)
		{
			m_Form = form;

			sfFTPLib.FTPConnectionMTA _ftp = new sfFTPLib.FTPConnectionMTA();
			
			_ftp.OnTransferProgress += new sfFTPLib.IFTPConnectionEvents_OnTransferProgressEventHandler(OnTransferProgress);

			// Host 
			_ftp.Host = url;
			_ftp.Port = port;
			_ftp.Username = username;
			_ftp.Password = password;
			_ftp.Passive = true;
			_ftp.Timeout = 60000;
			...

When I call the FTP code from within a new thread, the application crash on the line that access to LastTransferSpeed Value.

This sample works not: :unsure:
private void OnTransferProgress(int nTransferBytesLo, int nTransferBytesHi)
		{
			Int64 nTransferBytes = (uint)nTransferBytesLo;
			nTransferBytes <<= 32;
			nTransferBytes += (uint)nTransferBytesHi;
			int TransferSpeed = _ftp.LastTransferSpeed; // <---- crash here
			m_Form.label1.BeginInvoke(m_Form.m_DelegateShowTransferProgress, new Object[] { nTransferBytes.ToString() });
		}
Error in Line "System.NullReferenceException"
Any idea what's going on and how to fix this?

Thanks,
Raimund

#2 mb

mb

    Developer

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

Posted 13 May 2006 - 11:05 PM

Update to the latest version of SmartFTP FTP Library and try again.

Regards,
SmartFTP

#3 Raimund

Raimund
  • Members
  • 14 posts

Posted 16 May 2006 - 07:47 AM

Update to the latest version of SmartFTP FTP Library and try again.

Regards,
SmartFTP


Works fine. Thank you :unsure:

Regards,
Raimund




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users