private void ProcessFile(ImportFileInfo importFileInfo) { importFileInfo.MoveToFolder(ServiceConfiguration.Instance.StagingFilePath); var processWrapper = new ProcessWrapper(importFileInfo); processWrapper.SetLogger(_logger); processWrapper.OnTerminate += (sender, terminatingImportFile) => { ProcessWrapper tmp = null; _processRegistry.TryRemove(terminatingImportFile.Abi, out tmp); }; //Interlocked.Increment(ref _numRunningThread); _processRegistry[importFileInfo.Abi] = processWrapper; processWrapper.Start(); }
private void StartProcess(ImportFileInfo file) { file.MoveToFolder(ServiceConfiguration.Instance.StagingFilePath); //Log("Sposto il file in " + stagingFilePath); var importer = new FileImporter(file); importer.SetLogger(_logger); var processingThread = new Thread(() => { try { importer.Import(); }catch (Exception ex) { Log("Errore su thread"); } finally { lock (_lock) { _numRunningThreads--; _companyRegistry.Remove(file.Company); } //Interlocked.Decrement(ref _numRunningThreads); LogThreads(); } }); lock (_lock) { _numRunningThreads++; _companyRegistry.Add(file.Company); } //Interlocked.Increment(ref _numRunningThreads); processingThread.Start(); }
internal void ProcessFake() { Log("Processing " + importFileInfo); var _lock = new object(); if (0 == new Random().Next(3)) { Log("errore!!!"); throw new ImportException(); } for (long i = 0; i < 1000L; i++) { for (long j = 0; j < 1000000L; j++) { var res = Math.Sqrt(i * j); } if (_requestStop) { Log("Request stop " + importFileInfo); Thread.Sleep(3000 + new Random().Next(5) * 1000); Log("Stopped " + importFileInfo); return; } //for (long j = 0; j < 5000L; j++) //{ // var res = Math.Sqrt(i * j); //} //Thread.Sleep(5); } importFileInfo.MoveToFolder(ServiceConfiguration.Instance.CompleteFilePath); Log("Completed " + importFileInfo); }
public void Import() { Log("Avvio importazione :" + _importFile); // System.Threading.Thread.Sleep(4000 + new Random().Next(40) * 1000); //if (new Random().Next(3) == 0) //{ // Log("errore!!!!"); // throw new CustomException("Errore!!"); //} for (long i = 0; i < 1000L; i++) { for (long j = 0; j < 1000000L; j++) { var res = Math.Sqrt(i * j); } if (_requestStop) { return; } //for (long j = 0; j < 5000L; j++) //{ // var res = Math.Sqrt(i * j); //} //System.Threading.Thread.Sleep(3); } _importFile.MoveToFolder(ServiceConfiguration.Instance.CompleteFilePath); Log("Importazione completa :" + _importFile); // importa il file }