Custom Cut/Copy/Paste

S

Stumple

Hi,

I have created my own cut/copy/paste for visio.

Sometimes, when I try to cut a selection the entire application hangs and I
have to close it and restart.

This is the code I use:

Selection cutCopyPasteSelection = null;
this.cutCopyPasteSelection = visioCtl.Window.Selection;
this.cutCopyPasteSelection.Cut(VisCutCopyPasteCodes.visCopyPasteNormal);

Sometimes this code does work, so it doesn't always hang. Am I doing the
cut wrong? I copied the code from the sample in the documentation.

Thank you.
 
S

Stumple

Sorry, I posted the wrong code. It is not a Cut() that is hanging the visio
document. Those seem to work fine. It is instead the Copy() that hangs visio.

Selection cutCopyPasteSelection = null;
this.cutCopyPasteSelection = visioCtl.Window.Selection;
this.cutCopyPasteSelection.Copy(VisCutCopyPasteCodes.visCopyPasteNormal);
 
A

AlEdlund

this may not be the solution to what is happening, but, when I had a similar
problem I observed that it appeared to be the number of objects in the
selection that was causing the hang. The workaround was to create a group of
the selections before attempting the paste of the group.
al
 
S

Stumple

Do you think this is the same problem eventhough I have only one shape
selected? Is there a way to create a group of selections from on shape?

Thanks
 
A

AlEdlund

If it's only a single shape I doubt that it is the same problem. I ran into
it when the shape count got around 50 shapes. Do you have your code wrapped
with error trapping (try-catch-end try, on error, whatever) to catch what
might be failing?
al
 
S

Stumple

It is quite odd behavior and I am unsure how to track it down since it is
after I make a call to the visio code.

I did put a try-catch block around the code today just to catch anything
that might fall out in the future but I don't think that was the problem.
Before, I was just walking/stepping through the code one line at a time in
the debugger. I had actually set a beakpoint right before the .Paste() and
then tried to walk over the .Paste() line and that is when the whole
application locks up.

Today, I removed all breakpoints and just let the operation continue through
and it seems to be working properly, but without being able to put
breakpoints before and after the Paste() code I really have no way of
debugging my code because I perform special operations specific to the kind
of shape being copied.

Is there an event or something that needs to be processed in order for the
paste operation to succeed?

Thanks.
 
S

Stumple

I did try doing System.Windows.Forms.Application.DoEvents() and then placing
a breakpoint after that. So my code goes like this:

Paste()
DoEvents()
--Breakpoint--

What I saw was the copied shape drop onto the page and then my appliction
hung up. It appears the application only hangs if I have a breakpoint
somewhere after I do the paste. I am not sure what is going on though and why
a breakpoint would cause the application to hang.

Thanks.
 
A

AlEdlund

might not be the application, might be a system event since the visio is
unaware of break points.
al
 
S

Stumple

Something is going on. When the application hangs I right click it and tell
it to close and then I get a form for closing it and asking to restart it
when I close it. Then The current execution goes back to Visual Studio but I
am unable to change anything because VS is still waiting. Eventually I can
click the stop button at top of VS. I then have to wait for VS to prompt me
to stop debugging.
 
S

Stumple

I installed the C# Express 2008 and it seemed to fix my problem. It appears
MS has a problem with threads in VS 2005. It is a known issue which 2008
addresses.
 
A

AlEdlund

glad you've got a circumvention.
al

Stumple said:
I installed the C# Express 2008 and it seemed to fix my problem. It appears
MS has a problem with threads in VS 2005. It is a known issue which 2008
addresses.
 
P

Paul Herber

Hi,

I have created my own cut/copy/paste for visio.

Sometimes, when I try to cut a selection the entire application hangs and I
have to close it and restart.

This is the code I use:

Selection cutCopyPasteSelection = null;
this.cutCopyPasteSelection = visioCtl.Window.Selection;
this.cutCopyPasteSelection.Cut(VisCutCopyPasteCodes.visCopyPasteNormal);

Sometimes this code does work, so it doesn't always hang. Am I doing the
cut wrong? I copied the code from the sample in the documentation.

Something to bear in mind is that once the first paste has happened
then the Selection becomes invalid.
 

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