Need To Create Simple C# Windows App - Looks In Folder and Processes New Files Added [duplicate]

橙三吉。 提交于 2019-12-26 08:15:06

问题


Could someone please help me create a simple windows C# app that would look in a specified folder? The app basically will on the click of a button watch a specified folder and if a new file is put into the folder it opens the file and does some processing with it. I also need to consider if multiple files are created into the folder at relatively the same time.

I can create the project and the screen with Visual Studio, I just really need some help with creating the code to loop, watch and process files in the folder. I've tried using FileSystemWatcher but the problem is it will not process multiple files (or at least files that were put into the folder at the relative same time). Also it will not process a second file if it's added to the folder while the first file is being processed.

Any help or guidance on this would be really REALLY helpful. Please feel free to explain in great detail. :D


回答1:


According to this question: FileSystemWatcher vs polling to watch for file changes it is mostly a problem of the InternalBufferSize try to push that value a little up. But there are also some situations, where even that won't work e.g. network shares.

The alternative would be polling as said in the other question, which means that you need a list of the current files in the folder and a timer, that cyclic compares the items inside the folder with which are in the stored list.



来源:https://stackoverflow.com/questions/48288816/need-to-create-simple-c-sharp-windows-app-looks-in-folder-and-processes-new-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!