473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Cross Threading error on Wesbervice Completed Event

I have a dotnet 2.0 web service method that I execut asynchronously using the
auto generated method.
I catch the event using this
Private Sub Event_Completed(ByVal sender As Object _
, ByVal e As MyService.EventCompletedEventArgs) Handles
m_MyService.EventCompleted

me.text = e.Result.tostring

End Sub
I get a cross threading error when I update the text property of the form.

Where am I going wrong with this.
Mar 9 '06 #1
2 1130
Hi,

This happens because you are not allowed to update the user interface from
a non UI thread. Here's a C# solution (shouldn't be too difficult to convert
to VB)

this.Invoke(new MethodInvoker(
delegate()
{
this.Text = e.Result.ToString();
}
));

Also you may want to check out one of the episoder of DNR TV (http://dnrtv.com/default.aspx?showID=4).
I might be wrong but believe it has an example that should help you.

Best regards,
Robert Wilczynski

wi***************@gmail.com

I have a dotnet 2.0 web service method that I execut asynchronously
using the
auto generated method.
I catch the event using this
Private Sub Event_Completed(ByVal sender As Object _
, ByVal e As MyService.EventCompletedEventArgs) Handles
m_MyService.EventCompleted
me.text = e.Result.tostring

End Sub
I get a cross threading error when I update the text property of the
form.
Where am I going wrong with this.

Mar 9 '06 #2
Thank for Robert's input.

As for async webservice method, the callback procedure is executed in a
background thread which is different from the winform's executing UI
thread. Also, for winform form/controls, they're forced to be manipulated
in their UI thread only(due the win32 message based model). Here are some
other msdn articles have discussed on this:

#Safe, Simple Multithreading in Windows Forms, Part 1
http://msdn.microsoft.com/library/en...6112002.asp?fr
ame=true

#Give Your .NET-based Application a Fast and Responsive UI with Multiple
Threads
http://msdn.microsoft.com/msdnmag/is...toc.asp?frame=
true

Hope this also helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
1
by: Ajak | last post by:
Hi all, I would like to write a class (Task) with a method to do some lengthy process based on several of the class properties. The method is running on different thread. During the execution...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.