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

Thread and "callbacks"

GTi
Easy question for experts:

1)
I have a main application.
This application use a class in a library (MyLib)
ListenClass lc = new ListenClass();
I also have a "callback" class named
class GetListenDataClass(string data)
2)
I have a library (MyLib) that have a class ( ListenClass ) that again
creates a thread.
This thread will listen to a port and when data comes I want this
thread to send the data back to my main application :
GetListenDataClass(string data).

How can I do this?
Is this called delegates?
[Please use teaspoon when explaining it to me - I don't understand it]

Nov 17 '05 #1
5 2181
GTi
Whops... I think there is a small glitch in Google Groups today..... :)

Nov 17 '05 #2
GTi,

Either that, or you pushed send 6 times. Note that when you send something
it usually takes a few minutes for the post to show up.

Kind regards,
--
Tom Tempelaere.
"GTi" wrote:
Whops... I think there is a small glitch in Google Groups today..... :)

Nov 17 '05 #3
Gti,

"GTi" wrote:
Easy question for experts:

1)
I have a main application.
This application use a class in a library (MyLib)
ListenClass lc = new ListenClass();
I also have a "callback" class named
class GetListenDataClass(string data)
2)
I have a library (MyLib) that have a class ( ListenClass ) that again
creates a thread.
This thread will listen to a port and when data comes I want this
thread to send the data back to my main application :
GetListenDataClass(string data).

How can I do this?
Is this called delegates?
[Please use teaspoon when explaining it to me - I don't understand it]


The class which listens to the port should expose an event to which
subscribers that are interested in what is sent to the port can register.
I'll sketch this:

// listener (producer)
public delegate void IncomingDataHandler( string data );
public class IncomingDataListener
{
public event IncomingDataHandler IncomingData;
// ...
private void FireIncomingData( string data )
{
IncomingDataHandler l_IncomingData = IncomingData;
if( l_IncomingData != null )
l_IncomingData( data );
}
private void MonitorIncomingData( )
{
while( true )
FireIncomingData( GetIncomingData( ) );
}
private string GetIncomingData( )
{
// your port listener, blocks until data is available
// and returns it as string
}
}

// subscriber (consumer)
public class DataConsumer : IDisposable
{
private IncomingDataListener idl;
public DataConsumer( IncomingDataListener idl )
{
this.idl = idl;
idl.IncomingData += new IncomingDataHandler (
ConsumeIncomingData
);
}
public void Dispose( )
{
idl.IncomingData -= new IncomingDataHandler (
ConsumeIncomingData
);
}
private void ConsumeIncomingData( string data )
{
// consume data, don't forget to synchronize!
}
}

Kind regards,
--
Tom Tempelaere.
Nov 17 '05 #4
"TT (Tom Tempelaere)" wrote:
[...]
private void ConsumeIncomingData( string data )
{
// consume data, don't forget to synchronize!
ie, if this method accesses a shared resource.
}
}


HTH,
--
Tom Tempelaere.

Nov 17 '05 #5
GTi
TT (Tom Tempelaere) wrote:
GTi,

Either that, or you pushed send 6 times. Note that when you send something
it usually takes a few minutes for the post to show up.

Kind regards,
--
Tom Tempelaere.
"GTi" wrote:
Whops... I think there is a small glitch in Google Groups today..... :)


Yes and No...
The [Post message] button returned a service down error page. So I get
back waited and pressed the button again. Then after a few attempts it
worked OK again. But it posted the messages even that it gived med a
error.
I'm sorry about that.

Nov 17 '05 #6

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...
4
by: Robin Tucker | last post by:
Hi, I'm currently implementing a database with a tree structure in a table. The nodes in the tree are stored as records with a column called "Parent". The root of the tree has a "NULL" parent....
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
3
by: John | last post by:
Hi, I have a class which on instantiation creates a background thread to do its processing in. The class exposes a number of events that the application subscribes to so that data can be...
0
by: GTi | last post by:
Easy question for experts: 1) I have a main application. This application use a class in a library (MyLib) ListenClass lc = new ListenClass(); I also have a "callback" class named class...
2
by: Alfonso Morra | last post by:
Hi, I am writing a timer class that I want to be able to get to notify me (via a callback func), when a specified interval has elapsed. I have most of the timer functionality figured - however,...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
4
by: kk_oop | last post by:
Hi. I need to write a C++ callback function and register it with a C program. I've read that this can be done if the callback function is a static method. I've also read that I should use a...
6
by: Smithers | last post by:
Just looking to compile a list of "all the ways to implement events". I'm NOT looking to get into the merits or mechanics of each in this thread... just want to identify them all - good, bad, and...
19
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.