none
When calling Shell CopyHere command I need to know when operation complete

    Question

  • Hi,

    I have an operation that creates a number of large zip files.  At the moment I don't know when one is complete before starting the next one and the screen is full of lots (up to 30 sometimes) of zip windows.  For this reason, and knowing when some temporary folders are no longer being accessed so they can be deleted, I want to have only one zip operation at a time.

    I can't tell when that zip operation is finished though.  I have tried to use delegates as below but they are showing complete whilst they are clearly not complete:

     

    Folder SF = SH.NameSpace(fi.FullName);
    
    DirectoryInfo di = new DirectoryInfo(App.appSavePath);
    
    //Delegate for a Shell CopyHere
    
    ExportHelpers.CopyHereHandler handler = new ExportHelpers.CopyHereHandler(
    
    SF.CopyHere);
    
    foreach (DirectoryInfo diInner in di.GetDirectories())
    {
    
    
        string name = diInner.Name.ToLower();
    
        //If the directory is either not a language folder or is
    
        if (App.nonLanguageSubFolders.Where(a => a.ToLower() == name).Count() > 0
    
        || name == langId.ToLower())
        {
            Folder DF = SH.NameSpace(diInner.FullName);
    
            //SF.CopyHere(DF, 16);
    
            IAsyncResult result = handler.BeginInvoke(DF, 16, null, null);
    
            do
            {
    
                Thread.Sleep(250);
    
            } while (!result.IsCompleted);
        }
    }
    (Moderator: I put code into code block using </> button to make it *more* readable. Thx)


    The zipping works fine - but I would be very grateful if you could tell me how I can know, from .NET, when the Shell zip operation has completed so I can zip one folder at a time (the operation above is called many times for different folder structures - into separate zips).

    Thanks for any suggestions.

    Friday, November 20, 2009 1:17 PM

Answers

  • Hi,

    Are you using the Folder object in Shell Objects for Scripting and Microsoft Visual Basic to make ZIP files? Please correct me if I got it wrong.

    The CopyHere method works asynchronously when called on a ZIP file. That is to say, even you call the method directly without using BeginInvoke, it returns immediately if there is no error.

    So there is no way to workaround this by-design behavior.

    I suggest you try use a 3rd party .NET library (or write your own) to have the full control of the ZIP file generation. The Shell Objects for Scripting and Microsoft Visual Basic is just not a suitable tool here.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    • Marked as answer by raw100 Tuesday, November 24, 2009 8:39 AM
    Monday, November 23, 2009 11:17 AM

All replies

  • Hi,

    Are you using the Folder object in Shell Objects for Scripting and Microsoft Visual Basic to make ZIP files? Please correct me if I got it wrong.

    The CopyHere method works asynchronously when called on a ZIP file. That is to say, even you call the method directly without using BeginInvoke, it returns immediately if there is no error.

    So there is no way to workaround this by-design behavior.

    I suggest you try use a 3rd party .NET library (or write your own) to have the full control of the ZIP file generation. The Shell Objects for Scripting and Microsoft Visual Basic is just not a suitable tool here.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    • Marked as answer by raw100 Tuesday, November 24, 2009 8:39 AM
    Monday, November 23, 2009 11:17 AM
  • Hi,

    If "Shell Objects for Scripting and Microsoft Visual Basic" is the same as the interop.shell32.dll library then yes.  Ok - I'll look into 3rd party zipping libraries.

    Thanks,
    Monday, November 23, 2009 2:18 PM
  • If "Shell Objects for Scripting and Microsoft Visual Basic" is the same as the interop.shell32.dll library then yes.
    Yes, I believe we're talking about the same thing here.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    Tuesday, November 24, 2009 1:49 AM
  • For anyone that cares...

    I realize that the scripting object is not appropriate for any large scale Zip archiving tools, however, if you can't buy a Zip library... or do not like the free ones... this is not so bad an alternative except for the asynchronous archiving with no event handlers.

    The best way to determine when the asynch zipping is done is actually fairly simple... (even though its not perfect by any means and is a bit of Kludge... but it works)... it can be accomplished by comparing Item counts and sleeping the foreground thread until the item count in the zip archive is incremented. Its dumb, but it works and its relatively straight forward.

    foreach (string item in strPathItems) 

    {

    int instanceCount = 0, initialCount = zipFolder.Items().Count;

    zipFolder.CopyHere(item,256);

    while (instanceCount <= initialCount)

    {

    System.Threading.Thread.Sleep(100);

    instanceCount = zipFolder.Items().Count;

    }

    }


    ------------- This time... we didn't forget the gravy!
    Friday, January 27, 2012 9:27 PM