Пример #1
0
        private void DownloadFile(object sender, MouseButtonEventArgs e)
        {
            if (LBDialog.SelectedIndex >= 0)
            {
                string[] LocalTextFRomLB = FullTextOfDialog.Split('\n');
                if (LocalTextFRomLB[LBDialog.SelectedIndex].IndexOf("|") != -1)// TextToListBox[LBDialog.SelectedIndex].IndexOf("|") != -1
                {
                    ban = true;
                    string path;
                    if (!System.IO.File.Exists("SaveDefaultPath"))
                    {
                        FolderBrowserDialog Op = new FolderBrowserDialog();
                        Op.ShowDialog();
                        path = Op.SelectedPath;
                        System.IO.File.WriteAllText(@"SaveDefaultPath", path);
                    }
                    else
                    {
                        path = System.IO.File.ReadAllText(@"SaveDefaultPath");
                    }
                    //AsyncCallback callback=new AsyncCallback(sql.DownloadFileFromDB(StrmID, path));
                    Guid   StrmID     = new Guid(LocalTextFRomLB[LBDialog.SelectedIndex].Substring(0, LocalTextFRomLB[LBDialog.SelectedIndex].IndexOf("|")));
                    Thread FileThread = new Thread(delegate() { sql.DownloadFileFromDB(StrmID, path); });

                    FileThread.Priority = ThreadPriority.Normal;
                    FileThread.Start();

                    FileThread.Join();//ожидать завершение потока(Остановка всеъ тредов до завершения этого)
                    if (!FileThread.IsAlive)
                    {
                        ban = false;
                    }
                }
            }
        }