So you think the runtime will do the necessary synchronisation, right?

Are you sure I have to set the apartment state? If I remember correct, the
runtime will put any thread that is not assigned to an apartment into the
MTA if it uses COM interop. If Excel runs in a STA, shouldn't the COM
runtime marshal from the MTA to the STA? 

-----Ursprüngliche Nachricht-----
Von: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Im Auftrag von Dean Cleaver
Gesendet: Mittwoch, 1. Februar 2006 08:37
An: [email protected]
Betreff: Re: [ADVANCED-DOTNET] AW: [ADVANCED-DOTNET] Excel AddIn and Threads

"And the" = "as the" 

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Dean Cleaver
Sent: Wednesday, 1 February 2006 20:32
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] AW: [ADVANCED-DOTNET] Excel AddIn and Threads

On a usercontrol or form - not much use to you.

If you start any threads, ensure they have the same apartment state and the
calling thread:

Thread thread = new Thread(new ThreadStart(targetProc));
thread.SetApartmentState(System.Threading.Thread.CurrentThread.GetApartmentS
tate());

HHT
Dino

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Andreas Heisel
Sent: Wednesday, 1 February 2006 20:29
To: [email protected]
Subject: [ADVANCED-DOTNET] AW: [ADVANCED-DOTNET] Excel AddIn and Threads

On what object do you call 'Invoke.Required'?

-----Ursprüngliche Nachricht-----
Von: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Im Auftrag von Alex Smotritsky
Gesendet: Mittwoch, 1. Februar 2006 08:11
An: [email protected]
Betreff: Re: [ADVANCED-DOTNET] Excel AddIn and Threads

If in the background thread you're not accessing any shared resources you
may not need to do any synchronization. You can use BeginInvoke with a
delegate to call a function and put it on a background thread to do
background processing. Some people will use a callback to set off a function
that say accesses excel, I usually don't do that. I'll call that function at
the end of the method that does the background task. In that called function
I'll use if (Invoke.Required) to switch back to the ui thread if necessary
or not if the function doesn't touch the ui and then that function can do
whatever it needs to do.

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Andreas Heisel
Sent: Wednesday, February 01, 2006 1:37 AM
To: [email protected]
Subject: [ADVANCED-DOTNET] Excel AddIn and Threads

Hello,

I'm developing an Excel addin. I want to do some work on a background
thread. At the end of the background processing I need to access Excel to
insert some data into a worksheet.

Do I need to do any synchronisation as in a windows forms application? If I
need to, how should I do it? I haven't found an ISynchronizeInvoke
implementation.

Or does the runtime do the synchronisation? The Excel classes are COM
interop.


Andreas

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to