I know there are several question related to my issues, I've studied them all but it seems that I still can't get it. Something like this or like this.
I have a method that downloads some files through FTP (it takes somewhere around 5 seconds). When I click the button to download the files I also want to change a control property so that a "loading" kind of thing is visible.
For this I have a CircleProgressBar with "animated" property set by default to false. When I call the previous method I want first to change that property to true and after the download is complete to set it back to false as it was.
I tried many solutions but in vain:
void UpdateMessage(bool value)
{
Action action = () => DownloadLC_Normal_CircleProgressBar.animated = value;
Invoke(action);
}
private void DownloadLC_Normal_Button_Click(object sender, EventArgs e)
{
// try 1
//UpdateMessage(true);
// try 2
//DownloadLC_Normal_CircleProgressBar.Invoke((MethodInvoker)(() =>
//{
// DownloadLC_Normal_CircleProgressBar.animated = true;
//}));
// try 3
if (DownloadLC_Normal_CircleProgressBar.InvokeRequired)
{
DownloadLC_Normal_CircleProgressBar.BeginInvoke((MethodInvoker)delegate () { DownloadLC_Normal_CircleProgressBar.animated = true; });
}
else
{
DownloadLC_Normal_CircleProgressBar.animated = false;
}
// DOWNLOAD FILES THROUGH FTP BY CALLING A METHOD FROM A .cs FILE
// FROM THE PROJECT
//UpdateMessage(false);
//DownloadLC_Normal_CircleProgressBar.animated = false;
}
The CircleProgressBar never animates. What am I missing? What am I doing wrong, please? :(
EDIT: My missing part of code:
ftp ftpClient = new ftp("ftp://" + "192.168.1.200" + "/", "anonymous", "anonymous");
NetworkCredential credentials = new NetworkCredential("anonymous", "anonymous");
string url = "ftp://" + "192.168.1.200" + "/Documents and Settings/";
ftpClient.DownloadFtpDirectory(url, credentials, newDirectoryDownloadLocation);