Hi I wrote this little AddIn sample to show you a performance issue and how to avoid it
Can someone explain me why and how it works ?
It is just a parse of an excel workbook and runned in the main excel process (0) and a random thread created by the timer.
Thanks !
Public Class ThisAddIn
Dim a As System.Windows.Threading.Dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher()
Dim t As New Threading.Thread(New Threading.ParameterizedThreadStart(AddressOf threadTest))
Dim tm As New System.Timers.Timer(20000)
Delegate Sub TestHandler()
Dim tt As TestHandler = AddressOf test
Private Sub ThisAddIn_Startup() Handles Me.Startup
tm.AutoReset = True
tm.Start()
AddHandler tm.Elapsed, AddressOf threadTest
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Public Sub test()
Dim appE As Excel.Application = Globals.ThisAddIn.Application
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
End Sub
Private Sub threadTest()
' 800 ms
Dim o() As Object
a.Invoke(tt, o)
'12 seconds !
test()
End Sub
End Class