Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Shape.Select() is not working in threaded mode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
miztaken - 09 May 2008 08:04 GMT
Hi there,
I have some embedded jpg attachments in my DOC file.

I am extracting it like this:

shape.Select(ref nullobj);
shape.Application.Selection.CopyAsPicture();
IDataObject ido = Clipboard.GetDataObject();

ido will contain the object i want.

This code works fine in primary thread (Application thread)

But when i call the same thing from a method in my child thread, ido
returns null.

Whats is wrong here?

Thank You
miztaken
Jean-Guy Marcil - 09 May 2008 13:46 GMT
> Hi there,
> I have some embedded jpg attachments in my DOC file.
[quoted text clipped - 13 lines]
>
> Whats is wrong here?

What is "shape" in your code?

It seems to be a variable.

But "Shape" in important keyword (an Object name) in the Word Object model.
Doesn't this create conflicts when compiling?
miztaken - 09 May 2008 17:15 GMT
yes shape is a variable of type Shape Object name in Word Object
Model. Its just an instance of Words InlineShape type.
It wont produce any compilation errors.
shape.Copy() copies the shape (Inline or other shape) to Clipboard.
and we fetch the same but when used inside child thread its not
working.
Help me
Jean-Guy Marcil - 09 May 2008 18:43 GMT
> yes shape is a variable of type Shape Object name in Word Object
> Model. Its just an instance of Words InlineShape type.
> It wont produce any compilation errors.
> shape.Copy() copies the shape (Inline or other shape) to Clipboard.
> and we fetch the same but when used inside child thread its not
> working.

Nevertheless, it is bad practice to create variables bearing the same name
as reserved keywords.

Try changing the name, and even if it does not help, you should still change
the name becasue it is a bad idea to keep that name.

Maybe that in the child thread the compiler has difficulty resolving the
name...
Especially since you are using "shape" for an InlineShape, which are totally
different from Shapes. The compiler may react differently with this when you
are calling it in the child thread.

But I am now confused, you state:
"shape is a variable of type Shape Object name in Word Object Model. Its
just an instance of Words InlineShape type"
and then you go on to write:
"shape.Copy() copies the shape (Inline or other shape)"
So, which is it, shape or inline shape? They are different beasts. Depending
on how you create the instance, you may hve a problem. Is "shape" declared as
an Object , a Shape or an InlineShape?
miztaken - 11 May 2008 07:24 GMT
Hi Jean..
Ok i think i confused myself and you as well.
here is the code of that i am doing:

foreach (MsWord.InlineShape wordshape in doc.InlineShapes)
{
if(wordshape.Type==WdInlineShapeType.wdInlineShapePicture)
        {
                  wordshape.Select();
                  wordshape.Application.Selection.CopyAsPicture();
                  IDataObject ido = Clipboard.GetDataObject();
        }
}
here if i run this code (other supporting codes as well) in primary
thread then ido returns the Object but when its ran on child thread
then ido returns null.

I hope this is clear now.

Help me

miztaken
Cindy M. - 22 May 2008 15:36 GMT
Hi Miztaken,

Office is COM, so multi-threading isn't supported the same way. You
might want to read the information in these VSTO forum discussions -
they may give you an idea or help you figure it out

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=773041&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=850740&SiteID=1

> I have some embedded jpg attachments in my DOC file.
>  
[quoted text clipped - 10 lines]
> But when i call the same thing from a method in my child thread, ido
> returns null.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.