"File in use" error!

Topics: User Forum
Developer
Feb 19, 2007 at 11:51 AM
Hi guys,
I am having a problem palying back the created avi with windows media player for example. If i don't close the application, the file is in use, or it stays that way for
a random amount of time i believe.
This has become a problem to me since I create two avi's and then use splice again to join them. so when I try to add them it gives me media/file already in use. (as the HR return value).
this is the code i use to get the output:
Splicer.Renderer.IRenderer re = new Splicer.Renderer.AviFileRenderer(TL, outputfile, comp, null, null, null);
//re.Render();
IAsyncResult res = re.BeginRender(null, null);
re.EndRender(res);
//re = null;

Any hints??

Thanks alot

Fadi
Developer
Feb 19, 2007 at 1:43 PM
Fadik-

The file is not released until the comobjects are disposed of. This only happens when you dispose the renderer. Try calling re.Dispose().
Developer
Feb 20, 2007 at 6:42 AM
Edited Feb 20, 2007 at 6:54 AM
mille562,

Thank you for the suggestion, the RenderEngine object doesn't have a Dispose() method!

I just tried something.
I added a GC.Collect(); after the re=null; statement, and it was no
use, still the file is being locked by another process.

Out of curiosity, would this mean that probably there are comobjects not released in the splicer sourcecode upon render finish?
(maybe the solution would be to do a marshal.releasecomobj -not sure if its the right method name :)- in the render endrender method.)

Thank you for the help, and if you have anymore thoughts let me know please.

Regards,

Fadi
Developer
Feb 20, 2007 at 7:40 AM
mille562,

Thank you for the tip.
I went to the sourcecode and saw that the avifilerenderer did indeed implement
a destructor and dispose method.
So I noticed that the re object i am using is actually an IRenderer object created
with a "=new avirenderer(...)" method.
So I called the dispose method by casting the re object to AviRenderer and
it worked just fine.

Thank you again :)
Coordinator
Feb 20, 2007 at 11:00 PM
Apologies for chiming in late... Originally IRenderer did implement IDisposable, but I later removed it because it didn't necessarily make sense in all situations, I would suggest for you code that you just use the renderer classes directly, and obviously placing them inside a using statement will ensure cleanup i.e.

using (AviRender render = new AviRenderer(...))
{
// do whatever.
}
Developer
Jun 4, 2008 at 10:48 PM
Hi,
I found this thread after I had the same problem.  I am using WindowsMediaRenderer in the asynchronous mode (BeginRender()).  In the RenderCompleted event I call WindowsMediaRenderer.Dispose().  The file produced stays locked for some time after the dispose call.  I hit this problem when I try to delete the created file immediately after the RenderCompleted event.  Note that I am trying to delete the file on the main thread, not in the RenderCompleted event.  It seems that dispose returns before the underlying DS thread has finished with the file.  I guess this is probably a limitation of DS.  Is there any tidy way to work around this?  I'm considering simply waiting for the file to be released before deleting it.

Regards,
Felix