473,382 Members | 1,329 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,382 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 2182
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? ...
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: 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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.