Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2008, 01:25 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default cross thread exception

hi all!

I'm trying to create a utility that captures an image of a webpage based on the HTML from the source. I did some diging around and found that Windows Live makes an API with that functionality built in :) But when i try and use it i get the following error.

Code:
Uri uri = new Uri("http://www.msn.com");
WindowsLive.Writer.Api.HtmlScreenCapture hsc = new HtmlScreenCapture(uri, 800);

pictureBox1.Image = hsc.CaptureHtml(1000);

Error:
System.InvalidOperationException: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.

The line 'pictureBox`' refers to a control i have on my windows form.

When i call the basic
hsc.CaptureHtml(1000);

it returns the same error...

any ideas are welcome... Thanks in advance

Reply With Quote
  #2 (permalink)  
Old March 23rd, 2008, 06:46 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How is this block of code being called? Is this code being called from some other thread you created or in asynchronous operation?

This is the error you typically see if you spin off your own secondary threads (manually or use a "BackgroundWorker") to perform work that is trying to manipulate controls. The controls are "owned" by the initial/primary thread (this is the UI thread). No other thread can make changes to the controls created on the UI thread. You need to transition calls back to the UI thread to do this. This is usually done by calling the Invoke method on the form class that holds the control you want to change. The Invoke method invokes the handler provided to it on the thread it was created on, thus transitioning the control manipulation call back to the proper thread.

-Peter
peterlanoie.blog
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cross thread exception with windows live API YoungLuke C# 2008 aka C# 3.0 1 March 23rd, 2008 01:43 PM
Exception in thread "main" javax.xml.transform.Tra XSLTUser XSLT 1 December 29th, 2007 04:59 AM
cross thread Error angelboy C# 2005 1 July 28th, 2007 04:35 AM
Cross-thread operation not valid Richw71 C# 0 December 13th, 2006 09:17 AM
ERROR "Exception in thread "main" java.lang.NoClas nitinnishi BOOK: Beginning Java 2 3 June 17th, 2006 07:07 AM



All times are GMT -4. The time now is 02:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.