|
-
Dec 13th, 2005, 06:52 AM
#1
Thread Starter
Hyperactive Member
.NET 2.0 and Visio
I have a question. I open visio through my code. I have a treeview showing all of my shapes from that visio window. In VB6 I* was able to select the shape in the visio window and have it select it in my treeview through the event handler. In .NET it tells me I cannot do this because of crossthreading and the thread cannot directly manipulate the main thread.
Is there a workaround for this? I use basically the same code in VB6 and it works great.
Thanks.
Currently Using: VS 2005 Professional
-
Dec 13th, 2005, 10:34 AM
#2
Frenzied Member
Re: .NET 2.0 and Visio
Yes it is possible. VB is starting to force programers into using good coding habit like making thread safe calls. Here is a link to help you make you make thread safe calls (which is what you need).
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
-
Dec 13th, 2005, 06:59 PM
#3
Re: .NET 2.0 and Visio
It comes down to the fact that you were doing the wrong thing before but the compiler wasn't alerting you. The same thing happened VS.NET 2003, but VS 2005 will display many more compiler errors and warnings in an effort to make people write more robust code. The subject of using delegates to make cross-thread method calls can be a confusing one, but it is really relatively simple once you get the underlying concept. I've provided one or two simple examples in other threads.
http://www.vbforums.com/showthread.php?t=372737
-
Dec 13th, 2005, 09:50 PM
#4
Thread Starter
Hyperactive Member
Re: .NET 2.0 and Visio
How do I delegate another APP? I mean, I know of doing the WithEvents on the App but do you also delegate the app object??
Currently Using: VS 2005 Professional
-
Dec 13th, 2005, 10:07 PM
#5
Re: .NET 2.0 and Visio
 Originally Posted by tacoman667
How do I delegate another APP? I mean, I know of doing the WithEvents on the App but do you also delegate the app object??
I don't really understand what you're saying. Perhaps you should post the code that is causing the issue.
-
Dec 14th, 2005, 06:51 AM
#6
Thread Starter
Hyperactive Member
Re: .NET 2.0 and Visio
Basically it is my "Dim WithEvents App as Visio.Application". Then I watch the selectionchanged event from the visio app but in the eventhandler sub, i try to loop through my treenodes on my treeview and I get the error where I cannot manipulate items on the main thread, or whatever you get along those lines. After that I tried to create an event on myu main form that fired when the selectionchanged on the visio application, basically it was a double event fire, in hopes of having the event fire on the main thread but I get same results.
Any thoughts?
Currently Using: VS 2005 Professional
-
Dec 14th, 2005, 07:40 AM
#7
Re: .NET 2.0 and Visio
The problem is not the Visio.Application object but rather the TreeView. You cannot access members of a control in other than the UI thread, so you need to use a delegate to call a method that accesses the TreeView. It's exactly the same situation as in the example I linked to. You would just do whatever it is you want to do with your TreeView in the equivalent of the DoSomething method.
-
Dec 14th, 2005, 08:16 AM
#8
Thread Starter
Hyperactive Member
Re: .NET 2.0 and Visio
Can you delegate events or just subs/functions?
Currently Using: VS 2005 Professional
-
Jan 31st, 2006, 05:03 PM
#9
Thread Starter
Hyperactive Member
Re: .NET 2.0 and Visio
Question, I have my visio document shapes in a treeview. I want to select my shape on the visio window and have it automatically select the shape in my treeview. How do I do this through a safe thread-call?
Currently Using: VS 2005 Professional
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|