Last file converted being locked

tony.v

New member
I have developed an application that converts many files from .wtv to .ts using C# in WPF.

I have been able to get this to work; but only by using the InvokeMember technique - using the TypeLib DLL throws an error..

I am having an issue where the last file to be processed remains locked even after closing the file explicitly:

object[] vrd_filesave = new object[2];
vrd_filesave[0] = OutputFilename;
vrd_filesave[1] = null;

ret2 = (bool)vrd_type.InvokeMember("FileSaveAs", System.Reflection.BindingFlags.InvokeMethod, null, vrd_program, vrd_filesave);

if (ret2)
{
ret3 = 0;

do
{
ret3 = (int)vrd_type.InvokeMember("OutputGetState", System.Reflection.BindingFlags.GetProperty, null, vrd_program, null);
Thread.Sleep(TimeSpan.FromSeconds(1));
} while (ret3 != 0);

isSuccess = true;
}
else
{
isSuccess = false;
//MessageBox.Show("File " + file.FullName + " failed to save.", "Information",
// MessageBoxButton.OK, MessageBoxImage.Exclamation);
}

vrd_type.InvokeMember("FileClose", System.Reflection.BindingFlags.InvokeMethod, null, vrd_program, null);

This is the code. The lock remains even after I do the following:

vrd_type.InvokeMember("ProgramExit", System.Reflection.BindingFlags.InvokeMethod, null, vrd_program, null);

if (vrd_program != null)
{
Marshal.ReleaseComObject(vrd_program);
}
if (vrd != null)
{
Marshal.ReleaseComObject(vrd);
}

Have I got the FileClose wrong? I'm surprised the lock is still there after exiting the program.

Tony
 

tony.v

New member
Thank you for getting back to me.

I was told by Dan that it was okay for me to use the COM API.

Is that not right?
 

tony.v

New member
I fixed this by moving the whole of the VRD coding into a different process - actually a dialog using a progress bar. This forced the VRD objects to be released every time a file was converted.

Although slightly less efficient, it did the job.

Tony
 

Dan203

Senior Developer
Staff member
Just make sure you close VRD when you're done and you should be OK. The COM interface is basically just calling a hidden version of the main VRD program. So if you don't close it then it stays open and it's open handle on the file stays active. If you call close before you quit the thread then it's the same as clicking the X in the main dialog and should release all the file handles.
 

tony.v

New member
Yes. Things worked well once I did that.

Before that I had been instantiating the VRD object, looping through the videos, then closing the VRD object.

This is what I am used to being best practice.

When I did that, the last video file to be processed would be locked.

I still think it would be better if FileClose released that lock, but I have a solution that works now.

I am really pleased with the result and am now happily converting video files, in place, by specifying the file types to convert, what to convert to, and the root directory of the folders I want to process.

This suits the task I was trying to do using Batch Manager better for me.

Thanks for your help.

Tony
 
Top Bottom