473,799 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Event CompletedEventA rgs) Handles
m_MyService.Eve ntCompleted

me.text = e.Result.tostri ng

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 1147
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.ToStri ng();
}
));

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.Event CompletedEventA rgs) Handles
m_MyService.Eve ntCompleted
me.text = e.Result.tostri ng

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
5391
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 the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
77
2882
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 the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
77
3704
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 the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
1
1457
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 of the method, the class is suppose to fire events such as ProgressChanged. And it raises Completed and Failed event on completion and error
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.