What is wrong with my application ---- The size was 0, but I was expecting 46806!

I am a C # programmer.

Now I use ICSharpCode.SharpZipLib.dll to create a zip file in my current project. But it occurs to me that when I press a button in SECOND TIME to execute a function to create a zip file, the application will throw an exception, friendly and seriously tell me that "The size was zero, but I expected 46086."

I'm so confused that I want to know why? When I click the button for the first time, I can do it successfully without any errors.

My related codes are as follows:

internal void ThreadProc() { try { ZipHelper.CreateZip(backupZipFile, Constants.HomeConstant, true); // do other things } } 

The implementation of the CreateZip () function is as follows:

 public static void CreateZip(string zipFileName, string sourceDirectory, bool recurse) { FastZip zip = new FastZip(); if (File.Exists(zipFileName)) { File.Delete(zipFileName); } zip.CreateZip(zipFileName, sourceDirectory, true, ""); } 

Now I will show you the recursive call process:

  • Call method "UpdateAppAsync" in the class "ActiveCheckManager"
 public void UpdateAppAsync(string masterConfig) { this.masterConf = masterConfig; Thread actualThread = new Thread(new ThreadStart(UpdateApp)); actualThread.IsBackground = true; actualThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; actualThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; actualThread.Start(); } 
  1. Call the UpdateApp function asynchronously; in the UpdateApp method, it will only call the UpdateDetail function.
 private void UpdateDetail(string masterConfig, string category) { IUpdate worker = new HP.ActiveCheckLocalMode.UpdateEngine.UpdateManager(); worker.UpdateApp(masterConf); } 
  1. The .UpdateApp worker will only call UpdateDetail (string, UpdateCategory).
 private void UpdateDetail(string masterConfig, UpdateCategory cat) { UpdateThread updateThread = new UpdateThread(this, cat); updateThread.MasterConfig = masterConfig; updateThread.ThreadProc(); } 

This is the calling process. When I click the refresh button a second time, it will throw an exception, can you help me? Thank you very much.

+6
c # sharpziplib icsharpcode
source share
1 answer

Is the first task completed before you start the second time?

I would suggest that File.Delete () and some elements in SharpZipLib do not respond to anything in order to multi-user attach the same folder to the same file at the same time.

Encourage UpdateThread to updateThread as a private member of the ActiveCheckManager class, then verify that it is launched from a previous click before creating a new thread.

+1
source share

All Articles