473,397 Members | 1,949 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,397 software developers and data experts.

Raising event from async thread

Hello, I have a client/server application that needs to show forms depending
on what is received. The problem is that my Client class that handles all of
the sending and receiving of data raises it's DataReceived event in the
thread that is asyncronously reading the data from the tcpclient. This means
that I can't create any controls on my main form in the DataReceived event.
Does anyone know how I can raise the event in the main thread. Any help
would be appreciated. Thanks.

Joe
Nov 21 '05 #1
1 1165
Have your Client class inherit Control. Then, in your Client class, you can
use Me.Invoke to marshal back to the main thread before you raise your
event. Then the event handler in your form will be running on the correct
thread. I used this technique here:

http://msdn.microsoft.com/library/de...dunplugged.asp

Also, VS 2005 will solve this with a "BackgroundWorker" control. Juval has
written an implementation of that control that you can use today with VS
2003:

http://www.devx.com/codemag/Article/...k=DXRSS_DOTNET

(free, but registration required)

--
Scott Swigart
http://blog.swigartconsulting.com

"Joe Wright" <jo********@noventech.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello, I have a client/server application that needs to show forms
depending on what is received. The problem is that my Client class that
handles all of the sending and receiving of data raises it's DataReceived
event in the thread that is asyncronously reading the data from the
tcpclient. This means that I can't create any controls on my main form in
the DataReceived event. Does anyone know how I can raise the event in the
main thread. Any help would be appreciated. Thanks.

Joe

Nov 21 '05 #2

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

Similar topics

2
by: Chris Small | last post by:
Can anyone explain the difference between the two? Which is more reliable for large jobs?
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
7
by: Jeff Casbeer | last post by:
New to VB.. What is the VB syntax for posting a Windows event? For example, to have an event fire AFTER a form loads, I'd add a posted call to a "post_load" event, from "load". What is the VB...
3
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
9
by: CuriousGeorge | last post by:
Can someone explain why this code DOES NOT raise a null reference exception? //////////////////////////// Program.cs ///////////////////////////////////////////// using System; using...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have an app with the main thread and one additional thread. In the main thread I defined an event handler MyHandler, the function for raisin this event OnMyEvent and the function for...
26
by: buu | last post by:
So, let's say that a user enters an event name in text box, and would like to raise it.. is it possible to call events by their 'name'? Is it possible to enumerate events inside app. and to check...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...

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.