VSTO Powerpoint 在上传时保持加载光标处于暂停状态
VSTO Powerpoint Keep loading cursor on hold while uploading
我正在开发用于将视频导出和上传到我的服务器的 powerpoint 插件。在上传视频时,我想在 PowerPoint 上显示等待光标。
我已经使用 this code and this works fine. But if I use timer by this logic code,遇到光标变回默认值的问题。
var vstoPresentation = Globals.ThisAddIn.Application.ActivePresentation;
vstoPresentation.CreateVideo("path\to\filename.mp4");
// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler((s, e) => {
if (Globals.ThisAddIn.vstoPresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone)
{
// Executing my time-intensive hashing code here...
// uploading video to server
// when upload finished
// Set cursor as default arrow
Cursor.Current = Cursors.Default;
}
});
aTimer.Interval = 5000;
aTimer.Enabled = true;
最后,在翻阅许多博客和阅读官方文档后,我找到了解决方案。
var vstoPresentation = Globals.ThisAddIn.Application.ActivePresentation;
//declare a variable to check if video is uploading
public bool videoUploading = false;
//we need to register a "BeforeClose" handler
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.PresentationBeforeClose += new EApplication_PresentationBeforeCloseEventHandler(Application_PowerPointBeforeClose);
}
internal void upload(){
vstoPresentation.CreateVideo("path\to\filename.mp4");
// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler((s, e) => {
if (Globals.ThisAddIn.vstoPresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone)
{
Globals.ThisAddIn.videoUploading = true;
// Executing my time-intensive hashing code here...
// uploading video to server
// when upload finished
// Set cursor as default arrow
Cursor.Current = Cursors.Default;
Globals.ThisAddIn.videoUploading = false;
}
});
aTimer.Interval = 5000;
aTimer.Enabled = true;
}
private void Application_PowerPointBeforeClose(Presentation Pres, ref bool Cancel)
{
if (Globals.ThisAddIn.videoUploading == true)
{
DialogResult dialogResult = MessageBox.Show("Video upload is in progress, are you sure you want to abort?", "My Addin", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (dialogResult == DialogResult.No)
{
Cancel = true;
}
}
}
我正在开发用于将视频导出和上传到我的服务器的 powerpoint 插件。在上传视频时,我想在 PowerPoint 上显示等待光标。 我已经使用 this code and this works fine. But if I use timer by this logic code,遇到光标变回默认值的问题。
var vstoPresentation = Globals.ThisAddIn.Application.ActivePresentation;
vstoPresentation.CreateVideo("path\to\filename.mp4");
// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler((s, e) => {
if (Globals.ThisAddIn.vstoPresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone)
{
// Executing my time-intensive hashing code here...
// uploading video to server
// when upload finished
// Set cursor as default arrow
Cursor.Current = Cursors.Default;
}
});
aTimer.Interval = 5000;
aTimer.Enabled = true;
最后,在翻阅许多博客和阅读官方文档后,我找到了解决方案。
var vstoPresentation = Globals.ThisAddIn.Application.ActivePresentation;
//declare a variable to check if video is uploading
public bool videoUploading = false;
//we need to register a "BeforeClose" handler
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.PresentationBeforeClose += new EApplication_PresentationBeforeCloseEventHandler(Application_PowerPointBeforeClose);
}
internal void upload(){
vstoPresentation.CreateVideo("path\to\filename.mp4");
// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler((s, e) => {
if (Globals.ThisAddIn.vstoPresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone)
{
Globals.ThisAddIn.videoUploading = true;
// Executing my time-intensive hashing code here...
// uploading video to server
// when upload finished
// Set cursor as default arrow
Cursor.Current = Cursors.Default;
Globals.ThisAddIn.videoUploading = false;
}
});
aTimer.Interval = 5000;
aTimer.Enabled = true;
}
private void Application_PowerPointBeforeClose(Presentation Pres, ref bool Cancel)
{
if (Globals.ThisAddIn.videoUploading == true)
{
DialogResult dialogResult = MessageBox.Show("Video upload is in progress, are you sure you want to abort?", "My Addin", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (dialogResult == DialogResult.No)
{
Cancel = true;
}
}
}