저는 미디어 플레이어를 디자인하고 있으며 Movie 클래스를 디자인했습니다. Movie 클래스에는 MediaInfo에서 상속 한 MovieInfo 멤버가 있습니다. MediaInfo에는 파일 길이, 파일 크기, 파일 경로 등과 같이 동영상 파일의 메타 데이터를 나타내는 여러 가지 속성이 있습니다.이 정보를 추출하기 위해 Shell32를 사용합니다.Shell32 메서드 호출을 최적화하는 방법은 무엇입니까?
문제는 Shell32에서 제공되는 메서드가 매우 느린 것입니다. 데이터베이스에 1 개의 영화가 있으면 문제가되지 않지만 영화 10 편이되면 눈에 띄기 시작합니다. 영화 100 편으로 프로그램로드에 약 5 분이 걸리고 몇 분 안에 다시 초기화해야합니다. 런타임 동안 영화, 다시 프로그램의 흐름을 중단합니다.
/// <summary>
/// Gets a Shell32 Folder, initialized to the directory of the file path.
/// </summary>
/// <param name="path">A string representing the file/folder path</param>
/// <returns>The Shell32 Folder.</returns>
public static Folder GetShellFolder(string path)
{
//extract the folder subpath from the file path
//i.e extract "C:\Example" from "C:\Example\example.avi"
string directoryPath = new FileInfo(path).Directory.ToString();
return new Shell().NameSpace(directoryPath);
}
그리고 Shell32Processing.GetShellFolderItem 방법 :
/// <summary>
/// Gets a Shell32 FolderItem, initialized to the item specified in the file path.
/// </summary>
/// <param name="path">A string representing the file path.</param>
/// <returns>The Shell32 FolderItem.</returns>
/// <exception cref="System.ArgumentException">Thrown when the path parameter does not lead to a file.</exception>
public static FolderItem GetShellFolderItem(string path)
{
if (!FileProcessing.IsFile(path))
{
throw new ArgumentException("Path did not lead to a file", path);
}
int index = -1;
//get the index of the path item
FileInfo info = new FileInfo(path);
DirectoryInfo directoryInfo = info.Directory;
for (int i = 0; i < directoryInfo.GetFileSystemInfos().Count(); i++)
{
if (directoryInfo.GetFileSystemInfos().ElementAt(i).Name == info.Name) //we've found the item in the folder
{
index = i;
break;
}
}
return GetShellFolder(path).Items().Item(index);
}
호출 할 때마다
다음/// <summary>
/// Initializes all the information variables of the class.
/// </summary>
private void Initialize()
{
Folder mediaFolder = Shell32Processing.GetShellFolder(this.path);
FolderItem media = Shell32Processing.GetShellFolderItem(this.path);
//initialize bit rate value
this.bitrate = mediaFolder.GetDetailsOf(media, 28);
//initialize date accessed value
this.dateAccessed = mediaFolder.GetDetailsOf(media, 5);
//initialize date created value
this.dateCreated = mediaFolder.GetDetailsOf(media, 4);
//initialize date modified value
this.dateModified = mediaFolder.GetDetailsOf(media, 3);
//initialize data rate value
this.dataRate = mediaFolder.GetDetailsOf(media, 279);
//initialize file name value
this.fileName = mediaFolder.GetDetailsOf(media, 155);
//initialize file type value
this.fileType = mediaFolder.GetDetailsOf(media, 181);
//initialize folder value
this.folder = mediaFolder.GetDetailsOf(media, 177);
//initialize folder name value
this.folderName = mediaFolder.GetDetailsOf(media, 175);
//initialize folder path value
this.folderPath = mediaFolder.GetDetailsOf(media, 176);
//initialize frame height value
this.frameHeight = mediaFolder.GetDetailsOf(media, 280);
//initialize frame rate value
this.frameRate = mediaFolder.GetDetailsOf(media, 281);
//initialize frame width value
this.frameWidth = mediaFolder.GetDetailsOf(media, 282);
//initialize length value
this.length = mediaFolder.GetDetailsOf(media, 27);
//initialize title value
this.title = FileProcessing.GetFileTitle(this.path);
//initialize total bitrate value
this.totalBitrate = mediaFolder.GetDetailsOf(media, 283);
//initialize size value
this.size = mediaFolder.GetDetailsOf(media, 1);
}
가 Shell32Processing.GetShellFolder 방법입니다 :
Mediainfo를 생성자는 초기화 메소드를 호출 GetDetailsOf (Shell32에서 제공되는 코드)는 n 엄청난 처리 시간 - ANTS 프로파일 러를 사용하여이 프로그램을 찾았습니다. 처음에는 프로그램이 너무 느려졌는지 확인할 수 없었기 때문입니다.
그래서 질문입니다 : 어떻게 Shell32 메서드를 최적화 할 수 있습니까? 그렇지 않으면 대안이 있습니까?
당신을 감사 할 수 있습니다! 그게 문제를 완전히 고쳐주지는 못했지만, 여전히 눈에 띄는 지연이 있습니다. 그러나 지금은 훨씬 짧습니다. :) – Daniel
@Daniel 또한 COM 객체이므로 출시하는 것을 잊지 마십시오. 가장 정확한 방법을 보여주기 위해 위의 Initialize를 업데이트했습니다. 'Marshal'은'System.Runtime.InteropServices' (mscorlib)에 있습니다. – Tergiver
오, 그럴 필요가 있는지 몰랐습니다. 감사 :) – Daniel