예제 #1
0
        private void DownloadPhoto()
        {
            var pt = Values.SafeGetValue <PanelTile>("fileName");
            IEnumerable <string> directoryList = null;

            string fileName = ((File)pt.Tag).Name;
            string filePath = null;

            directoryList = FileTransfer.GetDirectoryNames(Values.SafeGetValue <TreeNode>("TreeNode"));

            foreach (string d in directoryList)
            {
                filePath += d + "/";
            }

            filePath += fileName;

            DownloadFileTokenSource = new CancellationTokenSource();
            Task.Factory.StartNew(() =>
            {
                bool success = false;
                string path  = null;
                Task <string> downloadTask           =
                    Task.Factory.StartNew(() => path = FileTransfer.DownloadFileTemp(filePath, out success));

                while (!downloadTask.IsCompleted && !DownloadFileTokenSource.IsCancellationRequested)
                {
                    Task.Delay(100).Wait();
                    if (DownloadFileTokenSource.IsCancellationRequested)
                    {
                        return;
                    }
                }

                if (success)
                {
                    View.FilePicture.InvokeSafe(c =>
                    {
                        View.FilePicture.SizeMode      = PictureBoxSizeMode.Zoom;
                        View.FilePicture.ImageLocation = path;
                    });
                }
            }, DownloadFileTokenSource.Token);
        }