I need the small help. I have written the File watcher function in c#. The requirement is that It should be continous in Loop. I have stored the different Files location in database. That is read from database and details stored in List object _fileLocationList.

When I execute its after one Loop I am getting Out Of Memory Exception" and application crash.

I have also tried the WHILE loop instead of GOTO:

Code :

protected List<FileLocation> _fileLocationList = new List<FileLocation>();
   _fileLocationList == GetFileLocation();


 public void StartFileWatchers()
        {
            try
            {
                Start :
                        logger.Log(LOG_TYPE.LOG_TYPE_FILE, "** Inside StartFileWatchers() Starting file watchers for each filelocation **");
                        foreach (FileLocation fileLocation in _fileLocationList)
                        {
                            try
                            {                                
                                Start(_cancelToken, DefaultFileDownloadInterval, fileLocation);
                            }
                            catch (Exception ex)
                            {
                                logger.Log(LOG_TYPE.LOG_TYPE_FILE, "Error inside Foreach Loop StartFileWatchers() " + ex);
                            }
                            finally
                            {
                                logger.Log(LOG_TYPE.LOG_TYPE_FILE, "Clear Memory inside finally ");
                                IDisposable disposable = _fileLocationList as System.IDisposable;
                                if (disposable != null) disposable.Dispose();
                            }
                        }
                        logger.Log(LOG_TYPE.LOG_TYPE_FILE, "Loop end ");
                goto Start;
                        }
            catch (Exception ex)
            {
                logger.Log(LOG_TYPE.LOG_TYPE_DATABASE, "Error inside StartFileWatchers " + ex, TYPE_MESSAGE.UNKNOWN_ERROR);
            }
        }

Error :

UNKNOWN_ERROR Message : Unable to update process entry so initiating shutdown : System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)

I would like to Iterate the LIST in infinite order (Run from start after end by foreach() or other way.).

Related posts

Recent Viewed