[更新2] VSTO AddIn中的性能问题(跨应用程序域编组) [英] [UPDATE 2] performance problem in VSTO AddIn (cross app domain marshalling)
问题描述
我正在为Office 2007编写Excel AddIn 使用VB中的VS2010,在与PowerPoint中的Excel对象模型交互时遇到严重的性能问题。
请在下面找到一个基本测试来演示问题(子测试())。
I’am writing an Excel AddIn for Office 2007 with VS2010 in VB, and I have severe performance issues when interacting with the Excel Object model from PowerPoint.
Please find below a basic test to demonstrate the issue (sub test()).
我们以4种不同的方式尝试了此代码,结果不同:
1. 直接从PowerPoint调用Excel对象模型:平均13 s
2.通过excel Addin托管的WCF服务从PowerPoint调用此代码:平均为9 s
3. 通过计时器从Excel Addin调用此代码(启动时,等待20秒并启动test()):9 s
4. 通过功能区按钮直接从Excel Addin调用代码:800ms
We tried this code in 4 different ways with different results :
1. Calling Excel object model directly from PowerPoint :on average 13 s
2. Calling this code from PowerPoint trough a WCF services hosted by an excel Addin : on average 9 s
3. Calling this code from an Excel Addin through a timer (at startup, wait 20 seconds and launch test()) : 9 s
4. Calling the code directly from an Excel Addin through a ribbon button : 800ms
I可以理解为什么1.缓慢的原因,因为代码与Excel不在同一个AppDomain中。
我也能理解为什么2.和3.因为代码没有在Addin中执行而变慢线程。
但我想不出任何其他解决方案来解决我的表现问题。
I can understand the difference why 1. is slow since the code is not in the same AppDomain as Excel.
I can also understand why 2. and 3. are slow since the code is not executed in the Addin Thread.
But I can't think of any additional solution to solve my performance issue.
最后我有两个问题。
1)当我说方法2和3因多线程而变慢时,我是否走在正确的轨道上?
In the end I have two questions
1) Am I on the right track when I say that method 2 and 3 are slow because of multithreading?
2)一般情况下,我如何使用.Net应用程序中的Excel对象模型而不会有这样的性能损失。
2) In general, how can I use Excel object model from a .Net Application and not have such a loss of performance.
谢谢提出您可能有的任何想法。
Thanks in advance for any ideas you might have.
Nicolas
Public Sub test(ByVal appE As Excel.Application)
Dim chrono As New System.Diagnostics.Stopwatch
chrono.Start()
appE.Interactive = False
appE.ScreenUpdating = False
Dim wb As Excel.Workbook = appE.ActiveWorkbook
Dim ws As Excel.Worksheet = wb.ActiveSheet
Dim rng As Excel.Range = ws.Cells(1, 1)
Dim nbit As Integer = 10000
For i = 1 To nbit
rng.Value = i
Next
appE.ScreenUpdating = True
appE.Interactive = true
chrono.Stop()
MsgBox(chrono.ElapsedMilliseconds.ToString + " " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString)
End Sub
推荐答案
Hi Avlin67 ,
Hi Avlin67,
感谢发布。我正在尝试让某人熟悉这个问题。所以,可能会有一些延迟。感谢您的耐心等待。感谢您的理解
。
最好的问候,
这篇关于[更新2] VSTO AddIn中的性能问题(跨应用程序域编组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!