PC Review


Reply
Thread Tools Rate Thread

Calling Excel methods from a different thread (COM add-in)

 
 
jklender@gmail.com
Guest
Posts: n/a
 
      11th Sep 2008
Hello all. I need to know if there is any way to this. I am using VS/
C# and COM interop to develop an Add-in for Excel.

I have a thread that tries to write on some cells of the current
spreadsheet. The problem is that when Excel is busy, these call return
an exception.


class MyClass {

Excel.Range cell;

public MyClass(Excel.Range cell) { this.cell = cell; }

// This method is called from a different thread than the original one
where the add-in starts
void AsynchronousWrite(object stuff)
{
cell.Value2 = stuff;
}
}

That throws the following exception when Excel is busy (for example
when the user is editing the content of a cell):

System.Runtime.InteropServices.COMException (0x800A03EC): Exception
from HRESULT: 0x800A03EC

Is there any straightforward way to solve this problem?

Thank you for your help.

 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      11th Sep 2008
In later versions you can check the app.Ready state, loop while false or
with a timer. Otherwise if you are sure there is no reason for the error, or
rather you get that particular error, similarly defer.

Perhaps after some determined time SendKeys (or API equivalent) an Esc in
case user has accidentally left Excel in edit mode (ensure Excel is the
active window)

Regards,
Peter T

<(E-Mail Removed)> wrote in message
news:6a6a77e6-379e-4090-8f9f-(E-Mail Removed)...
> Hello all. I need to know if there is any way to this. I am using VS/
> C# and COM interop to develop an Add-in for Excel.
>
> I have a thread that tries to write on some cells of the current
> spreadsheet. The problem is that when Excel is busy, these call return
> an exception.
>
>
> class MyClass {
>
> Excel.Range cell;
>
> public MyClass(Excel.Range cell) { this.cell = cell; }
>
> // This method is called from a different thread than the original one
> where the add-in starts
> void AsynchronousWrite(object stuff)
> {
> cell.Value2 = stuff;
> }
> }
>
> That throws the following exception when Excel is busy (for example
> when the user is editing the content of a cell):
>
> System.Runtime.InteropServices.COMException (0x800A03EC): Exception
> from HRESULT: 0x800A03EC
>
> Is there any straightforward way to solve this problem?
>
> Thank you for your help.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Main thread calling event from child thread without using Ctrl.Inv =?Utf-8?B?Tm91bG91aw==?= Microsoft Dot NET Framework Forms 7 5th Jul 2006 01:58 AM
thread calling methods Pohihihi Microsoft C# .NET 6 6th Jan 2006 10:27 PM
Calling a main thread method from a worker thread Hao L Microsoft C# .NET 5 2nd May 2005 08:31 PM
Calling Thread.Suspend and it's affect on the target thread... Paul Tomlinson Microsoft C# .NET 1 3rd Feb 2005 11:14 PM
Calling Main Thread from a worker thread in vb.net Documentation Peter Microsoft VB .NET 1 1st Nov 2004 07:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.