Answered Question about release IFileSystemImage

  • Friday, July 02, 2010 9:10 AM
     
     

    I'm using IFileSystemImage to do some data burning, and I can't release FSI object after CreateResultImage. The files on the hard disk can't be delete...

    if blank CD, occasionally I can delete files after burn,

    if non-blank CD, I can never delete files after burn.

    1.First, I use SHCreateStreamOnFile to create IStream, and add it to  FSI.root.

    Code Snippet

                try
                {
                    Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream);

                    if (stream != null)
                    {
                        rootItem.AddFile(displayName, stream);
                        return true;
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (stream != null)
                    {
                        int iReturn = Marshal.FinalReleaseComObject(stream);
                    }
                }

    2.Second, CreateFsisystem

    Code Snippet

                MsftFileSystemImage fileSystemImage = null;
                IFileSystemImageResult fileSystemImageResult = null;
                IFsiDirectoryItem rootItem = null;
                try
                {
                    fileSystemImage = new MsftFileSystemImage();
                    fileSystemImage.ChooseImageDefaults(discRecorder);
                    fileSystemImage.FileSystemsToCreate =
                      FsiFileSystems.FsiFileSystemJoliet | FsiFileSystems.FsiFileSystemISO9660;
                    fileSystemImage.VolumeName = m_BurnData.ClientName;

                    fileSystemImage.Update += fileSystemImage_Update;
                    if (multisessionInterfaces != null)
                    {
                        fileSystemImage.MultisessionInterfaces = multisessionInterfaces;
                        FsiFileSystems fsi = fileSystemImage.ImportFileSystem();
                        fsi = fileSystemImage.IdentifyFileSystemsOnDisc(discRecorder);
                    }


                    rootItem = fileSystemImage.Root;

                    foreach (IMediaItem mediaItem in m_ListItems)
                    {
                        if (backgroundBurnWorker.CancellationPending)
                        {
                            break;
                        }

                        mediaItem.AddToFileSystem(ref rootItem);
                    }

                    fileSystemImage.Update -= fileSystemImage_Update;

                    if (backgroundBurnWorker.CancellationPending)
                    {
                        dataStream = null;
                        return false;
                    }

                    fileSystemImageResult = fileSystemImage.CreateResultImage();
                    dataStream = fileSystemImageResult.ImageStream;
                }
                catch (COMException exception)
                {
                }
                finally
                {
                    if (rootItem != null)
                    {
                        Marshal.FinalReleaseComObject(rootItem);
                    }
                    if (fileSystemImageResult != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystemImageResult);
                    }
                    if (fileSystemImage != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystemImage);
                    }
                }

    3.After discFormatData.Write(dataStream)

    Code Snippet

     Marshal.FinalReleaseComObject(dataStream);

    Marshal.FinalReleaseComObject(discRecorder);

    Marshal.FinalReleaseComObject(discFormatData);

All Replies

  • Tuesday, July 06, 2010 5:13 PM
    Moderator
     
     Proposed

    Hi Susie,

    You'll need to narrow down the issue: try to do the same things:
    without event subscribing,
    without event subscribing & burning,
    without event subscribing & burning & image creation,
    etc.

    Once you get the point, which causes the problem, it should be easy to fix the issue.

    With Regards,
    Mikhail

  • Tuesday, July 27, 2010 9:24 PM
     
     Answered

    Closing due to no response.  If the user comes back with more information, we can reopen.

     

    Best Regards,

    Windows Optical Team

  • Monday, August 02, 2010 2:54 AM
     
     

    Hi Mikhail,

    I'm sorry for being late, about this question I modified someplaces. Now,Only when the disk is rewriteable, and is non-blank, I can't delete files after burn.

    Except format the rewiteable disc before burn, is there any other solution?

    Best Regards,

    Susie

  • Tuesday, August 03, 2010 1:56 AM
     
     

    After Burn I release these com object.

    code snippet

                    if (discRecorder != null)
                    {
                        Marshal.FinalReleaseComObject(discRecorder);
                        discRecorder = null;
                    }

                    if (discFormatData != null)
                    {

                        if (discFormatData.Recorder != null)
                        {
                            Marshal.FinalReleaseComObject(discFormatData.Recorder);
                            discFormatData.Recorder = null;
                        }

                        Marshal.FinalReleaseComObject(discFormatData);
                        discFormatData = null;
                    }
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                        fileSystem = null;
                    }

    When the disc is rewriteable and non-blank, I can't delete files. But if I comment out the line //discFormatData.Write(fileSystem); after release com object, I can delete files. So I think when write, something is locked. Now which com object should be released?

  • Thursday, June 02, 2011 3:35 AM
     
     
    I also have same problem. I am not able to delete the files on the hard disk once do a discFormat.Write(fileSystem). Anyone working on IMAPI have any idea? Strangely it locks only the first file out of the lot always! Susie did you find any solution for this?
  • Wednesday, November 23, 2011 9:08 PM
     
     

    Anyone ever get an answer to this, I have been beating my head all day trying to get past this issue.

    I have called marshal.ReleaseComObject on the filesystem image, IStream, MsftDiscFormat2Data and nothing seems to make a difference.

     

    I am desperate at this point.