Excel, .Net and threads

  • Thread starter Thread starter Graham
  • Start date Start date
G

Graham

I have been asked by a client to produce a proof of concept of how .Net performs and works within an Excel workbook. Everything works perfectly with all the required events firing and data being read from the correct cells.
I sent this to the client and he is happy but asked some questions, and Im not too sure on the answers (he is an old school VBA developer at heart and doesn't know anything about .Net):
 
Hi Graham,

AS for the
=========
.Net performs and works within an Excel workbook
=========

you mentioned, do you means using .NET to Automate the office Excel
workbook or use .NET based add-in components or something like the .net
based SmartDoc interfaces?

For .NET based Automation code, they're just a managed wrapper of the COM
interfaces All the instances are created by the underlying COM
infrastructure and be wrappered by managed code so as to make use of the
managed programming language's feature.

For those .NET based Add-in or SMARTDoc compoenents, they're hosted inside
the word/excel's unmanaged process, but be separated from the unmanaged
code. All the managed class instances or controls be controled in CLR
runtime (managed thread/ heaps....). Of course, all the Control and their
events will be fired in the same UI thread.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Graham" <[email protected]>
| Subject: Excel, .Net and threads
| Date: Mon, 19 Sep 2005 14:27:13 +1200
| Lines: 91
| MIME-Version: 1.0
| Content-Type: multipart/alternative;
| boundary="----=_NextPart_000_001C_01C5BD26.3A40CF60"
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222-153-55-149.jetstream.xtra.co.nz 222.153.55.149
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125412
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have been asked by a client to produce a proof of concept of how .Net
performs and works within an Excel workbook. Everything works perfectly
with all the required events firing and data being read from the correct
cells.
| I sent this to the client and he is happy but asked some questions, and
Im not too sure on the answers (he is an old school VBA developer at heart
and doesn't know anything about .Net):
|
----------------------------------------------------------------------------
----
| The only potential issue is whether the menu is calling the same thread
of the .NET class or a new thread. I suspect it is the same thread each
time (good) and assume that your core .NET class is declared global-static
as there is no memory churn when the menus and events are running. The
problem we had with Excel 97 was that it did not support global static
classes and therefore any variable that needed to be a global variable was
not necessarily global. The use of a static function to instantiate the
class was the workaround.
|
----------------------------------------------------------------------------
----
| I believe that everything is running in the same thread and their is only
one instance of the Application and WorkBook objects.
| Can somone please confirm or deny these statements.
| Thanks
|
 
Im using Visual Studio Tools for Office 2003 and creating a new workbook
project in Visual Studio,
so I think its "using .Net to automate the office Excel workbook", is this
right?
Graham
 
Hi

The VSTO approach is similar with Automation, it does use the Office Object
Modal to manipulate the Office Application.
Based on my research, the VBA approach/VSTO code behind apporach will run
the code all on the Excel UI thread.
e.g. We will try to popup a msgbox in a VBA macro or in the VSTO code
behind, they will all run on the Excel UI thread, commonly it is the first
thread in the process.

For the VSTO in .NET, when the Excel is loaded, it will try to check
certain properties in the document and try to load the CLR to host the
managed dll. Because the Office Code behind code is managed code, it will
only run in the CLR, and then the CLR will JIT it into unmanaged code to
run. This is how CLR/.NET works. So the .NET class is inside the CLR, it is
host CLR in the Excel process to run the managed code.

For detailed information about CLR hosting, I recommend you may take a look
at the book below which explained that.
Customizing the Microsoft .NET Framework Common Language Runtime
(Pro-Developer (Paperback)) (Paperback)
http://www.amazon.com/exec/obidos/tg/detail/-/0735619883/102-8672265-1264963
?v=glance

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
You're welcome Graham,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Graham" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Excel, .Net and threads
| Date: Thu, 22 Sep 2005 11:59:59 +1200
| Lines: 42
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222-153-144-23.jetstream.xtra.co.nz 222.153.144.23
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:126274
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thank you both for your helpful answers
|
| | > Hi
| >
| > The VSTO approach is similar with Automation, it does use the Office
| > Object
| > Modal to manipulate the Office Application.
| > Based on my research, the VBA approach/VSTO code behind apporach will
run
| > the code all on the Excel UI thread.
| > e.g. We will try to popup a msgbox in a VBA macro or in the VSTO code
| > behind, they will all run on the Excel UI thread, commonly it is the
first
| > thread in the process.
| >
| > For the VSTO in .NET, when the Excel is loaded, it will try to check
| > certain properties in the document and try to load the CLR to host the
| > managed dll. Because the Office Code behind code is managed code, it
will
| > only run in the CLR, and then the CLR will JIT it into unmanaged code to
| > run. This is how CLR/.NET works. So the .NET class is inside the CLR,
it
| > is
| > host CLR in the Excel process to run the managed code.
| >
| > For detailed information about CLR hosting, I recommend you may take a
| > look
| > at the book below which explained that.
| > Customizing the Microsoft .NET Framework Common Language Runtime
| > (Pro-Developer (Paperback)) (Paperback)
| >
http://www.amazon.com/exec/obidos/tg/detail/-/0735619883/102-8672265-1264963
| > ?v=glance
| >
| > Best regards,
| >
| > Peter Huang
| > Microsoft Online Partner Support
| >
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "AS IS" with no warranties, and confers no
| > rights.
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top