gpt4 book ai didi

c# - 如何在 Powerpoint 插件中让 Powerpoint SaveAs WMV 具有高优先级?

转载 作者:行者123 更新时间:2023-11-30 18:32:52 24 4
gpt4 key购买 nike

我的任务是在将当前 powerpoint 保存为 WMV 后获取电影帧。以下代码作为独立应用程序运行良好,但由于“CreateVideoStatus”作为 Powerpoint 加载项运行时始终为“PpMediaTaskStatus.ppMediaTaskStatusQueued”而陷入无限循环。我的猜测是因为 SaveAs WMV 操作很耗时,所以操作系统降低了它的优先级,直到 CPU 被插件本身释放。有人可以帮帮我吗?提前致谢。

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

var app = this.Application;
var pres = app.Presentations;
var file = pres.Open("F:\\Src\\Culturelization\\animation2.pptx");
file.SaveAs("F:\\Src\\Culturelization\\SimpleDemo\\simple.wmv", PowerPoint.PpSaveAsFileType.ppSaveAsWMV, Office.MsoTriState.msoTrue);
Boolean isExporting = true;
do
{

Thread.Sleep(1000);
if (file.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusFailed && file.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone)
{
isExporting = false;
}

} while (isExporting);

}

最佳答案

  1. 您可以使用新线程来检查“powerpoint 另存为 wmv”状态。
    如:BackgroundWorker,避免你的主程序hold住。

  2. 在你的循环条件中有一个逻辑错误:

    if ( file.CreateVideoStatus == ppMediaTaskStatusFailed && file.CreateVideoStatus == ppMediaTaskStatusDone )

    “CreateVideoStatus”一次只有一个状态。
    使用“||” (或)不是“&&”(和)。

引用代码:

using System.ComponentModel;

namespace AddInName
{
public partial class ThisAddIn
{
private BackgroundWorker checkSave_backgroundWorker = new BackgroundWorker();

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
checkSave_backgroundWorker.DoWork += new DoWorkEventHandler(checkSave_backgroundWorker_DoWork);
}

// ...

private void DoSave()
{
Globals.ThisAddIn.Application.ActivePresentation.SaveAs( saveAsWmvFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsWMV, Microsoft.Office.Core.MsoTriState.msoTrue );
checkSave_backgroundWorker.RunWorkerAsync();
}


private void checkSave_backgroundWorker_DoWork( object sender, DoWorkEventArgs e )
{
bool isDone = false;
do
{
Thread.Sleep( 1000 );
if ( Globals.ThisAddIn.Application.ActivePresentation.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone
|| Globals.ThisAddIn.Application.ActivePresentation.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusFailed
|| Globals.ThisAddIn.Application.ActivePresentation.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusNone )
{
isDone = true;
}
} while ( !isDone );

// Finish!
}
}
}

关于c# - 如何在 Powerpoint 插件中让 Powerpoint SaveAs WMV 具有高优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com