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

Question about Multithreading

Hello everyone,
I am implementing a multithreaded tcp client with two classes,
cNetworkManager class and cUI Class, I created a secondary thread for
receiving packets using blocking "Receive" method in cNetworkManager and when
a packet is received I want to raise an event to cUI Class, but I don't want
to raise that event on my secondary thread, so does anyone know how can I
notify my main thread in cNetworkManager so the thread could raise the event
for cUI class.

Regards,
Aug 16 '06 #1
3 1142
Jefe wrote:
I am implementing a multithreaded tcp client with two classes,
cNetworkManager class and cUI Class, I created a secondary thread for
receiving packets using blocking "Receive" method in cNetworkManager and when
a packet is received I want to raise an event to cUI Class, but I don't want
to raise that event on my secondary thread, so does anyone know how can I
notify my main thread in cNetworkManager so the thread could raise the event
for cUI class.
You'll need to use an ISynchronizeInvoke reference to call
Invoke/BeginInvoke/EndInvoke on. UI controls all implement this
automatically, but you'll need to pass it to the NetworkManager class
(eg in the constructor) so that it's got something to communicate with.

Jon

Aug 16 '06 #2
Hi Jon,
Tnx for the reply, could you give a code sample or a url which has the sample?
"Jon Skeet [C# MVP]" wrote:
Jefe wrote:
I am implementing a multithreaded tcp client with two classes,
cNetworkManager class and cUI Class, I created a secondary thread for
receiving packets using blocking "Receive" method in cNetworkManager and when
a packet is received I want to raise an event to cUI Class, but I don't want
to raise that event on my secondary thread, so does anyone know how can I
notify my main thread in cNetworkManager so the thread could raise the event
for cUI class.

You'll need to use an ISynchronizeInvoke reference to call
Invoke/BeginInvoke/EndInvoke on. UI controls all implement this
automatically, but you'll need to pass it to the NetworkManager class
(eg in the constructor) so that it's got something to communicate with.

Jon

Aug 16 '06 #3
Jefe wrote:
Tnx for the reply, could you give a code sample or a url which has the sample?
Well, for simple UI work, see
http://www.pobox.com/~skeet/csharp/t...winforms.shtml

Just pass in a reference to a control as an ISynchronizeInvoke to the
class which needs to do the marshalling to the UI thread, and the rest
of the code should be very similar.

Jon

Aug 16 '06 #4

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

Similar topics

0
by: Jean-Yves Nief | last post by:
hello, I have written a script which is performing some tasks in multithreading mode: the main thread is opening a connection to a distant server and all the threads that I start will have to...
1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
1
by: Jeff Yang | last post by:
These days,I have read the artile "Safe, Simple Multithreading in Windows Forms, Part 1" on MSDN,and I also runed the example of it....
2
by: Silent Ocean | last post by:
Hi All I have following questions regarding C# Assembly and Threading. Let me know the precise answer or lead me to the proper materials. 1. Is memory leakeage possible in .Net Manager...
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
2
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.