Results 1 to 9 of 9

Thread: .NET 2.0 and Visio

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    .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

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .NET 2.0 and Visio

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: .NET 2.0 and Visio

    Can you delegate events or just subs/functions?
    Currently Using: VS 2005 Professional

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    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
  •  



Click Here to Expand Forum to Full Width