Shape.Select() is not working in threaded mode

M

miztaken

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
 
J

Jean-Guy Marcil

miztaken said:
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?

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?
 
M

miztaken

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
 
J

Jean-Guy Marcil

miztaken said:
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?
 
M

miztaken

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
 
C

Cindy M.

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.

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.

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 :)
 

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

Top