3. How to make visible that bytestransferred are updated. When i send the file the application stops and run after upload.
Firstly, if you really only want to be notified that the file upload has completed then you should use the FTPConnection.Uploaded event. Secondly, can you please post the code that you've put in your event-handler? We should be able to tell you how the deadlock occurs if we see the code.
I finally get a way to do it but i think it must be a better way than a thread. This is my solution:
namespace PolaczenieFTP
{
public partial class Form1 : Form
{
public string[] filenames;
public FTPConnection ftp;
public OpenFileDialog openFile;
public FileInfo fi;
Thread watek;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFile = new OpenFileDialog();
openFile.Filter = "All files (*.*)|*.*";
openFile.Multiselect = true;
openFile.RestoreDirectory = true;
if (openFile.ShowDialog() == DialogResult.OK)
{
filenames = openFile.FileNames;
ftp = new FTPConnection();
ftp.ServerAddress = "xxxx";
ftp.UserName = "xxxx";
ftp.Password = "xxxx";
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.DeleteOnFailure = true;
ftp.TransferType = FTPTransferType.BINARY;
ftp.EventsEnabled = true;
ftp.TransferNotifyInterval = 4000;
ftp.BytesTransferred += new BytesTransferredHandler(ftp_B);
ftp.Connect();
ftp.Uploaded += new FTPFileTransferEventHandler(zuploadowany);
watek = new Thread(new ThreadStart(upload));
watek.Start();
}
}
public void zuploadowany(object s, FTPFileTransferEventArgs ex) {
listBox1.Items.Add(ex.RemoteFile.ToString()+" zdarzenie dziala");
}
public void ftp_B(object s, BytesTransferredEventArgs e)
{
label1.Text = e.ByteCount.ToString()+"/"+fi.Length;
}
public void upload()
{
for (int i = 0; i < filenames.Count(); i++)
{
fi = new FileInfo(filenames[i]);
ftp.UploadFile(filenames[i], "nowy" + i + ".jpg");
}
}
public void formClosing(object sender, FormClosingEventArgs ev)
{
try
{
watek.Abort();
}
catch (NullReferenceException e) { }
}
private void button2_Click(object sender, EventArgs e)
{
watek.Abort();
}
}
}
Can i give upload nad another methods in another class and then put it into a thread or thats will be bad solution ???
In uploaded event will be some code that puts information about images in MySQL database. (after uploading an image)
Please tell me is that good way to do it. It will be an service application to read some orders for an image(format,how many...) adding galeries and images to the galeries...
Thank you for the reply.