J'essaie de créer un add-in C# excel 2007, et je veux faire "plus vite" la méthode "beforeSave". J'utilise simplement un thread (et j'essaie aussi la tâche et task.factory) mais il dit toujours la même erreur.C# excel beforesave thread
Le code.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WorkbookBeforeSave += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave);
}// thisAddIn_startup method end
public void Application_WorkbookBeforeSave(Microsoft.Office.Interop.Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel)
{
backendworker bwfs = new backendworker();// its a custom standalone class!
Task task1 = new Task(() => bwfs.MyBeforeSave(this.Application.ActiveWorkbook));
task1.Start();
}// application_workbookbeforesave method end
la classe backworker:
public class backendworker
{
// BeforeSave method
public void MyBeforeSave(Microsoft.Office.Interop.Excel.Workbook Wb)
{
Wb.SaveCopyAs("c:\\temp\\temp.xls");
}// method end
}// class end
Sans fil (tout type) son accord, il peut enregistrer le classeur entier. MAIS. avec toute soulution multithread son erreur de lancer. (Exception de HRESULT: 0x800AC472)
Une idée de ce que je fais mal? Ou idée comment le réparer? : D
Je ne recommanderais pas d'essayer d'accéder au cross-thread 'Application'. – climbage
Que se passe-t-il dans BeforeSave qui est "trop lent"? –
Il semble qu'il ne soit pas recommandé d'utiliser un autre thread mais une interface utilisateur: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/9168f9f2-e5bc -4535-8d7d-4e374ab8ff09/ – danielQ