Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Download temporizzato - pool thread
Forum - C# / VB.NET - Download temporizzato - pool thread

Avatar
patrizio_84 (Normal User)
Newbie


Messaggi: 1
Iscritto: 25/11/2009

Segnala al moderatore
Postato alle 16:09
Mercoledì, 25/11/2009
Salve a tutti, sono nuovo e non so nemmeso se c'è una discussione già aperta..
Ho un mega problemone:

ho un array e una listview per mostrare questo array,
la listview serve solo per far vedere all'utente i cambi di stato dei file.
L'array è formato e ordinato secondo gli orari dei file, ora la questione è:
quando il timer è uguale a uno o + orari-file parte un controllo presenza del file sul server e reperisce la cartella dove devo salvare perchè ogni file ha una cartella specifica, se la risposta è affermativa parte il download.

1) mi seleziona solo il primo file con lo stesso orario del timer,
2) se il download non è finito e ne parte un'altro si impalla tutto il sistema

mi aiutate per favore?????javascript:addsmile(':d')

Questo è il codice che nn funziona

        private void Carica_lista_AUTO()
        {
            try
            {
                progressBarTOT.Value = 0;
                LoadFiles();
            }
            catch
            {
                AggiungiElementoAlFileDiLOG("ERRORE 102");
            }
        }

        private void LoadFiles()
        {
            lstFiles.Items.Clear();
            for (int i = 0; i < listBox6.Items.Count; i++)
            {
                string testoitem = listBox6.Items.ToString();
                char[] delimiterChars = { '/' };
                string[] words1 = testoitem.Split(delimiterChars);
                string orario = words1[0];
                string nome = words1[1];
                ListViewItem item = new ListViewItem();
                item.Text = nome;
                item.SubItems.Add("In attesa");
                item.SubItems.Add(orario);
                lstFiles.Items.Add(item);
            }
            timerVAI.Enabled = true;
        }

        private void timerVAI_Tick(object sender, EventArgs e)
        {
            try
            {
                controlla_ORA_seleziona_ROW();
            }
            catch
            {
                AggiungiElementoAlFileDiLOG("ERRORE 201");
            }
        }

        private void controlla_ORA_seleziona_ROW()
        {
            try
            {
                int K = 0;
                lista_nomi_file_selezionati = new Automatic_TIPO_NOME[listBox6.Items.Count];
                lista_URLfolder_selezionati = new Automatic_URL_DESTINAZIONE[listBox6.Items.Count];
                for (int g = 0; g < listBox6.Items.Count; g++)
                {
                    string testoitem = listBox6.Items[g].ToString();
                    char[] delimiterChars = { '/' };
                    string[] words1 = testoitem.Split(delimiterChars);
                    string orario = words1[0];
                    if (GetTime() == orario)
                    {
                        lstFiles.Items[g].Selected = true;
                        lista_nomi_file_selezionati[g].NOME_File = words1[1];
                        lista_nomi_file_selezionati[g].TIPO_File = words1[2];
                        lstFiles.Items[g].EnsureVisible();
                        K++;
                    }
                    MessageBox.Show(lstFiles.SelectedItems.Count.ToString());
                    listBox8.Items.Add(lista_nomi_file_selezionati[g].NOME_File.ToString() + "-" + lista_nomi_file_selezionati[g].TIPO_File.ToString());
                }
            }
            finally
            {
                if (lista_nomi_file_selezionati[0].NOME_File != null)
                {                
                    thrLEGGIlista_AUTO = new Thread(new ThreadStart(Contolla_Selezioni_AUTOMATICO));
                    thrLEGGIlista_AUTO.Start();
                }
            }
        }

        private void Contolla_Selezioni_AUTOMATICO()
        {
            try
            {
                for (int i = 0; i < lista_nomi_file_selezionati.Length; i++)
                {
                    string url = dammi_nome_server_funzionante_selezioni(lista_nomi_file_selezionati.NOME_File);
                    string cartella = dammi_FOLDER_AUTO(lista_nomi_file_selezionati.TIPO_File);
                    if (url != "" && url != null)
                    {
                        lista_URLfolder_selezionati.ESITO_File = "1";
                        lista_URLfolder_selezionati.FOLDER_File = cartella;
                        lista_URLfolder_selezionati.URL_File = url;
                        listBox7.Items.Add(lista_URLfolder_selezionati.ESITO_File + "-" + lista_URLfolder_selezionati.FOLDER_File + "-" + lista_URLfolder_selezionati.URL_File);
                    }
                    else
                    {
                        lista_URLfolder_selezionati.ESITO_File = "0";
                        listBox7.Items.Add(lista_URLfolder_selezionati.ESITO_File);
                    }
                }
            }
            catch
            {
                AggiungiElementoAlFileDiLOG("ERRORE 202");
            }
        }

        private string dammi_nome_server_funzionante_selezioni(string nome_file)
        {
            string[] Server_temp = new string[ListaServerOrdinata.Length];
            Server_temp = ListaServerOrdinata;
            string server_OK = null;
            for (int i = 0; i < ListaServerOrdinata.Length; i++)
            {
                Application.DoEvents();
                bool esito = controllaServerFunzionanti_AUTO(Server_temp + nome_file);
                if (esito == true)
                {
                    server_OK = Server_temp;
                    break;
                }
            }
            return server_OK;
        }

        private bool controllaServerFunzionanti_AUTO(string URL_server_con_nomeFile)
        {
            string URL = URL_server_con_nomeFile;
            bool esito = false;
            WebClient mywebclient = new WebClient();
            try
            {
                byte[] mydatabuffer = mywebclient.DownloadData(URL);
                string download = Encoding.ASCII.GetString(mydatabuffer);
                if (download != null || download != "")
                {
                    esito = true;
                }
                return esito;
            }
            catch
            {
                esito = false;
                return esito;
            }
        }

        private string dammi_FOLDER_AUTO(string tipologia)
        {
            string folder = null;
            for (int u = 0; u < listBoxTipo_Folde.Items.Count; u++)
            {
                string testoitem = listBoxTipo_Folde.Items.ToString(); ;
                char[] delimiterChars = { '-' };
                string[] words1 = testoitem.Split(delimiterChars);
                string tipo = words1[0];
                if (tipologia == tipo)
                {
                    folder = words1[1];
                    break;
                }
            }
            return folder;
        }

PM Quote