Demand is such, through the web transmission over the picture, whether it is JS upload, or other upload method, you need to generate 2 thumbnails, respectively, for the product list of the small figure small, and for the share of the small figure share. Depending on the different upload methods, the EXE program can be used to easily fit all situations, so there are the following solutions. First is the use of simple filewatcher, we only need to listen to the Create event. Because small and share are all in the same folder, there is no need to monitor changes to subfolders. this.filewatcher.path = Tbdir.text;filewatcher.notifyfilter = Notifyfilters.lastwrite | notifyfilters.lastaccess | Notifyfilters.filename | Notifyfilters.creationtime;filewatcher.includesubdirectories = false; #region Trigger event filewatcher.created + = new FileSystemEventHandler (filewatcher_create); #endregion where filewather_create is the key implementation method, there will be a pit. File upload needs to consider the integrity of the upload file, that is, if the following code to obtain picture information, because the image size is incorrect, or the picture file is corrupted, resulting in the picture compression failed. image Imgphoto = Image.FromFile (FilePath) Therefore, here I can only simply think that a picture can be uploaded within 2 minutes (because before uploading, you can use the text prompt way, Prompt the user not to upload too big picture), simply sleep a bit. thread.sleep, String filePath = E.fullpath; filezip (FilePath, E.name); when implementing the Filezip method, You need to consider the Dispose picture file, and use GC to clean up the cache, otherwise there is a risk of out-of-memory behavior. The specific implementation code is not detailed here. In order to ensure the integrity of the thumbnail, listen to the folder at the same time, using the timer, every 30 minutes to all the pictures to do a traverse check, the uncompressed image is re-compressed. while (true) { Thread.Sleep ($ * +); Allfilezip ();} Start debugging, seemingly normal operation, rest assured to go to bed ...
Through Filewatcher, listen to images uploaded via the web and compress