CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Location
    Ottawa, ON, Canada
    Posts
    34

    Access Paragraph created in non-UI thread?

    The main class initializes a List<Paragraph> object. New paragraphs are created in a new Task and added to the list of paragraphs. Upon Task completion the paragraph list is scanned in order to append the individual paragrahs to a RichTextBox. However, I get "The calling thread cannot access this object because a different thread owns it" and I suppose it means that paragraphs created in a non-UI thread cannot be access in the UI thread.

    Anyone know a workaround for this? Thanks.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Access Paragraph created in non-UI thread?

    You communicate between threads by the use of delegates. You can pass a method to your non-UI thread that can be executed on the UI thread periodically or when the task is complete. If you use a BackgroundWorker it is even easier; just handle the DoWork event (and a couple others).

  3. #3
    Join Date
    Apr 2009
    Location
    Ottawa, ON, Canada
    Posts
    34

    Re: Access Paragraph created in non-UI thread?

    Is there a limit to the number of BeginInvoke() calls that the main thread Dispatcher can enqueue for later processing? Thanks.
    Last edited by tr00don; October 21st, 2010 at 10:35 AM.

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

Featured