how to hold the second process unless first process completes?
<p>I'm unzipping a encrypted zip folder then i decrypted it. The issue i'm facing is when deleting Folder 2 "File is being used by another process" why? I think <code>FolderZipper.ZipUtil.ZipFiles</code> occupies the folder 2 anyway I need to delete the files after this lock section has fully completed. i failed with lock() operation. 
give me yor suggesstion.</p>

<pre><code>lock (this)
{
 FolderZipper.ZipUtil.UnZipFiles(_strLocalFilePath, _strHTMLTemp, "", false);\\say folder 1;
 DecryptZipFile(_strHTMLTemp, _strLocalUserIDDeviceID);\\say Folder 2
 FolderZipper.ZipUtil.ZipFiles(_strLocalUserIDDeviceID + "\\" + _strFileNameWithoutExtension, _strLocalUserIDDeviceID + "\\" + _strFileNameWithEx, "");
}

 DirectoryInfo _Dir = new DirectoryInfo(_strHTMLTemp);
 _Dir.Delete(true);              \\deleting folder 1  
 DirectoryInfo _Direct = new DirectoryInfo(_strLocalUserIDDeviceID + "\\" + _strFileNameWithoutExtension); \\deleting folder 2
 _Direct.Delete(true);
</code></pre>

<hr>

<p><strong>Edit:</strong>
Zip Util Class:</p>

<pre><code>public static class ZipUtil
{
    public static void ZipFiles(string strInputFolderPath, string strOutputPathWithFileName, string strPassword)
    {
        ArrayList ar = GenerateFileList(strInputFolderPath); // generate file list
        int TrimLength = (Directory.GetParent(strInputFolderPath)).ToString().Length;
        // find number of chars to remove   // from orginal file path
        TrimLength += 1; //remove '\'
        FileStream ostream;
        byte[] obuffer;
        //string outPath = inputFolderPath + @"\" + outputPathAndFile;
        string outPath =  strOutputPathWithFileName;
        ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); // create zip stream
        if (strPassword != null &amp;&amp; strPassword != String.Empty)
            oZipStream.Password = strPassword;
        oZipStream.SetLevel(9); // maximum compression
        ZipEntry oZipEntry;
        foreach (string Fil in ar) // for each file, generate a zipentry
        {
            oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
            oZipStream.PutNextEntry(oZipEntry);

            if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
            {
                ostream = File.OpenRead(Fil);
                obuffer = new byte[ostream.Length];
                ostream.Read(obuffer, 0, obuffer.Length);
                oZipStream.Write(obuffer, 0, obuffer.Length);
            }
        }
        oZipStream.Finish();
        oZipStream.Close();
    }


    private static ArrayList GenerateFileList(string Dir)
    {
        ArrayList fils = new ArrayList();
        bool Empty = true;
        foreach (string file in Directory.GetFiles(Dir)) // add each file in directory
        {
            fils.Add(file);
            Empty = false;
        }

        if (Empty)
        {
            if (Directory.GetDirectories(Dir).Length == 0)
                // if directory is completely empty, add it
            {
                fils.Add(Dir + @"/");
            }
        }

        foreach (string dirs in Directory.GetDirectories(Dir)) // recursive
        {
            foreach (object obj in GenerateFileList(dirs))
            {
                fils.Add(obj);
            }
        }
        return fils; // return file list
    }


    public static void UnZipFiles(string strZipPathWithFileName, string strOutputFolderPath, string strPassword, bool deleteZipFile)
    {
        ZipInputStream s = new ZipInputStream(File.OpenRead(strZipPathWithFileName));
        if (strPassword != null &amp;&amp; strPassword != String.Empty)
            s.Password = strPassword;
        ZipEntry theEntry;
        string tmpEntry = String.Empty;
        while ((theEntry = s.GetNextEntry()) != null)
        {
            string directoryName = strOutputFolderPath;
            string fileName = Path.GetFileName(theEntry.Name);
            // create directory 
            if (directoryName != "")
            {
                Directory.CreateDirectory(directoryName);
            }
            if (fileName != String.Empty)
            {
                if (theEntry.Name.IndexOf(".ini") &lt; 0)
                {
                    string fullPath = directoryName + "\\" + theEntry.Name;
                    fullPath = fullPath.Replace("\\ ", "\\");
                    string fullDirPath = Path.GetDirectoryName(fullPath);
                    if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
                    FileStream streamWriter = File.Create(fullPath);
                    int size = 2048;
                    byte[] data = new byte[2048];
                    while (true)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size &gt; 0)
                        {
                            streamWriter.Write(data, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }
                    streamWriter.Close();
                }
            }
        }
        s.Close();
        if (deleteZipFile)
            File.Delete(strZipPathWithFileName);
    }
}
</code></pre>
