Poor performance of WPF application reading from Excel on separate thread

I have some code in my project that reads from and writes into Excel 2003 using Excel COM API. Now this piece of code is called from two places: 1. From within the Excel add-in itself, on the same thread. 2. From a WPF application, where the WPF window was invoked on a separate thread.

The issue is, when the WPF application invokes the code, the normal operation of reading from Excel that should take 10 seconds is taking 2 minutes. I think it is because of the invocation from a new thread, but I'm not 100% sure.

Any ideas?

Answers


You have a number of things to consider:

  • The COM API likely launches the Excel process. It takes time to start the process and wait for it to be ready.
  • There is likely a process boundary being crossed, this is slower than in-proc stuff.
  • You may have fallen into the trap of thread-affinity of the COM objects you create in code. They might have affinity with the thread they were created on, meaning even though you use a COM object on another thread, the actual running of that code is marshalled back to the owning thread of the object. This should be obvious, however, as your UI will stutter if the code is intensive enough.

Sorry this isn't a direct answer, but it gives some points to explore.


Need Your Help

How to trigger ViewModel command for a specific button events

wpf button mvvm command mouseevent

How can a command on a ViewModel be invoked by a specific event of a button, such as MouseDoubleClick?

vs 2012: Shims compile

visual-studio-2012 shim microsoft-fakes

I am trying to make a shim in VS 2012 ultimate as it described in MSDN site:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.