protected override void ThrCicloReadInputBufferAndElaborateMainQueue() { Thr.SbloccaThrPadre(); Thread thrAvvioUL; Int32 numElemInUpl; DateTime timeoutStart; //UInt64 indiceProssElem; IOrderedEnumerable <KeyValuePair <UInt64, UploadItem> > elementiDaUpl; //indiceProssElem = 1; #if DEBUG == false try { #endif while (true) { Thread.Sleep(9); ControlloElementiEStatistiche(); numElemInUpl = (from tmp in this.queue where tmp.Value.UploadState == UplItemState.UplAvviato select tmp).Count(); if (numElemInUpl >= this.config.MaxParallelStreams) { continue; } if (this.raggiuntoMaxKBSec) { continue; } elementiDaUpl = from tmp in this.queue where tmp.Value.UploadState == UplItemState.Iniziale orderby tmp.Value.Priority ascending, tmp.Key ascending select tmp; //ho messo il >= indiceProssElem poichè se dovesse succedere che il metodo Accoda salta una chiave, //questo thread non si incanterà, esiste anche il metodo first e firstOrDefault, il primo da eccezione se la query linq non restituisce elementi, nel secondo per il parametro default non si può usare nothing if (elementiDaUpl.Count() == 0) { continue; } thrAvvioUL = Thr.AvviaNuovo(() => ThrAvvioUpload(elementiDaUpl.ElementAt(0).Value)); timeoutStart = DateTime.Now; while (true) //Check operation start on item { if (elementiDaUpl.ElementAt(0).Value.UploadState != UplItemState.Iniziale) { break; //operation started } if ((DateTime.Now - timeoutStart).TotalSeconds > timeoutToStartSec) { elementiDaUpl.ElementAt(0).Value.DescErr = "TimeoutToStart di " + timeoutToStartSec + " secondi raggiunto, url:<" + elementiDaUpl.ElementAt(0).Value.url + ">"; Log.main.Add(new Mess(elementiDaUpl.ElementAt(0).Value.tipoLogTimeout, "", "per l'url:<" + elementiDaUpl.ElementAt(0).Value.url + ">, " + elementiDaUpl.ElementAt(0).Value.DescErr)); elementiDaUpl.ElementAt(0).Value.UploadState = UplItemState.TimeoutToStart; break; } Thread.Sleep(1); } //indiceProssElem = elementiDaUpl.ElementAt(0).Key + 1; } #if DEBUG == false } catch (Exception ex) { Thr.NotificaErrThrCiclo(ex, true); } #endif }
protected override void ThrCicloReadInputBufferAndElaborateMainQueue() { Thr.SbloccaThrPadre(); DateTime timeoutStart; //UInt64 indiceProssElem; IOrderedEnumerable <KeyValuePair <UInt64, DownloadItem> > elementiDaDwl; DownloadItem elemDownload = null; //indiceProssElem = 1; #if DEBUG == false try { #endif while (true) { Thread.Sleep(9); while (inputBuffer.Count > 0) { if (Concur.Queue_TryDequeue(inputBuffer, ref elemDownload) == false) { break; } idItem += 1; elemDownload.IdItemInList = idItem; Concur.Dictionary_TryAddOrUpdate(queue, new KeyValuePair <UInt64, DownloadItem>(idItem, elemDownload), noUpadate: true); } ControlloElementiEStatistiche(); ItemInProcessing = (from tmp in this.queue where tmp.Value.DownloadState == DwlItemState.DwlAvviato select tmp).Count(); if (ItemInProcessing >= this.config.MaxParallelStreams) { continue; } if (this.raggiuntoMaxKBSec) { continue; } elementiDaDwl = from tmp in this.queue where tmp.Value.DownloadState == DwlItemState.Iniziale orderby tmp.Value.Priority ascending, tmp.Key ascending select tmp; //A parità di priority prendo il più vecchio in coda ItemToProcess = elementiDaDwl.Count(); if (ItemToProcess == 0) { continue; } elemDownload = elementiDaDwl.ElementAt(0).Value; //Serve poichè gli elementi della LinQ si aggiornano all'istante quando un parametro della where o della orderby cambiano Thread thrDL = Thr.AvviaNuovo(() => ThrAvvioDownLoad(elementiDaDwl.ElementAt(0).Key)); timeoutStart = DateTime.Now; while (true) //Check operation start on item { if (elemDownload.DownloadState != DwlItemState.Iniziale) { break; //operation started } if ((DateTime.Now - timeoutStart).TotalSeconds > timeoutToStartSec) { elemDownload.DescErr = "TimeoutToStart di " + timeoutToStartSec + " secondi raggiunto, url:<" + elemDownload.url + ">"; Log.main.Add(new Mess(elemDownload.tipoLogTimeout, "", "per l'url:<" + elemDownload.url + ">, " + elemDownload.DescErr)); elemDownload.DownloadState = DwlItemState.TimeoutToStart; break; } Thread.Sleep(1); } Thread.Sleep(config.SleepAfterOneOperationMs); //while (elemDownload.DownloadState == DwlItemState.DwlAvviato) //{ // Thread.Sleep(1); //} //indiceProssElem = elementiDaDwl.ElementAt(0).Key + 1; } #if DEBUG == false } catch (Exception ex) { Thr.NotificaErrThrCiclo(ex, true); } #endif }