Cross-thread operation not valid

Topics: CAB & Smart Client Software Factory
Aug 31, 2006 at 3:56 PM
originally posted by: MichaelDaniel

Hi,
I'm having issues with threading in my smart client app.
After loading my view, the presenter calls a smart Web Service to retrieve a collection of data for a gridview on the View.
I've paraphrased the calls below:

GetMyData(DataFilter filter)
{
MyDataManager.GetData(bool success, MyData[] myData)
{
if(success)
View.BindMyData(myData);
}
}

In MyDataManager.cs I have a method similar to the following:

GetData(DataFilter filter, MyDataDelegate callback)
{
// make asynchronous call to web service here

}

The issue is that I am now getting a "Cross-thread operation not valid" error whenever these calls are made. How can I specify that the calls need to be made on the UI thread?
Thansk for any help.
M.
Aug 31, 2006 at 7:57 PM
originally posted by: askew

The BankBranchWorkbench SCSF implementation has something to search for and examine in "GetCustomerAccounts". The Event Broker is used, and the 'ThreadOption.UserInterface' is specified on the subscription side. The asynchronous web call publishes the event when the web service data is ready, and the subscriber gets in on the UI thread.
Sep 1, 2006 at 11:02 AM
originally posted by: eugeniop

There's also a specific section of the documentation that explains this: ms-help://ms.scsf.2006jun/SCSF/html/03-090-UI%20Threading.htm

See under "Useful Patterns for Smart Client Applications" UI Threading.
Sep 1, 2006 at 11:10 AM
originally posted by: marianoszklanny

Also, you will find useful the developer Hands On Labs of the SC-SF. In Lab 4 you can find guidance on creating Smart Web References and showing results of web service calls in a View.

You can download it from the Downloads section of this workspace:
http://www.gotdotnet.com/codegallery/releases/viewuploads.aspx?id=941d2228-3bb5-42fd-8004-c08595821170

Mariano Szklanny
http://staff.southworks.net/mariano