Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
AnswerAnswer! Pin
Nagy Vilmos1-May-09 0:11
professionalNagy Vilmos1-May-09 0:11 
AnswerAnswer Pin
dan!sh 1-May-09 0:12
professional dan!sh 1-May-09 0:12 
AnswerRe: Question! Pin
SimpleData1-May-09 0:19
SimpleData1-May-09 0:19 
QuestionProblem with events code and thread (long post) Pin
Otex30-Apr-09 23:02
Otex30-Apr-09 23:02 
AnswerRe: Problem with events code and thread (long post) Pin
Nicholas Butler1-May-09 0:35
sitebuilderNicholas Butler1-May-09 0:35 
GeneralRe: Problem with events code and thread (long post) Pin
Otex1-May-09 0:48
Otex1-May-09 0:48 
AnswerRe: Problem with events code and thread (long post) Pin
Nicholas Butler1-May-09 5:22
sitebuilderNicholas Butler1-May-09 5:22 
QuestionRe: Problem with events code and thread (long post) Pin
Otex3-May-09 5:43
Otex3-May-09 5:43 
Nick, thanks for your answer I am very glad you took interest in that issue, it seems nobody is interestd in what I thought would be an interesting problem.

I have re-read the excellent tutorial from Joseph Albahari, even that there are no references on how events are handeled in threads it is still useful

The code I have posted is obviously not an application, it is just a part of a test application that will allow me to create the code for the larger one, to narrow the problem I have stripped all the un-necessary parts before posting here.

If we confine the problem to the Test application the goal is to implement an obscure serial protocol (ASTM) and to test with the other party that can be client or server.

Data can be sent to the serial port from the UI thread or from another thread in the Test app, it can also be received at any time and forwarded to the UI and/or to another thread, at that time the UI may or may not be running hence the reason to separate the serialport thread to handle the serialcomms. Also if I run all my code in the UI thread the UI freezes until I get answers from the other party, the protocol specifies extended retries and delays, another reason to have an other thread for the serial comms.

If you have time and kindness to discuss the suitability of the architecture to the task I would be delighted to provide more info for you to appreciate.

Now back to the problem.
From what you said I gather that upon binding the event a thread will be created and it will be sleeping until an event is fired.
The part I am unsure is the life of the instance and the source thread, lets say I instantiate a class CLassA with 10 methods MethodA-MethodJ from the UI thread, then in the constructor I attach the received_data event to a method, say MethodA.
When the event received_data is fired it will launch MethodA, MethodA could launch MethodB, MethodC, and an event in MethodC will send data via another event and delegate to the UI.

- Event that the event handler for Recived_data was created from the UI thread it is in it's own thread now so I assume MethodA-C will run in a different thread than the UI, is it correct ?

- What is the life of the instance of ClassA if not used for a long time ? will the garbage collector delete it ? does the garbage collector only deletes threads and not instances ?

Thanks
AnswerRe: Problem with events code and thread (long post) Pin
Nicholas Butler3-May-09 7:43
sitebuilderNicholas Butler3-May-09 7:43 
QuestionHow to Pass TableAdapter data to another form's datagrid for modification then return the data to the original TableAdapter Pin
MarkB12330-Apr-09 22:59
MarkB12330-Apr-09 22:59 
AnswerRe: How to Pass TableAdapter data to another form's datagrid for modification then return the data to the original TableAdapter Pin
Christian Graus30-Apr-09 23:49
protectorChristian Graus30-Apr-09 23:49 
Questionload settings.settings in an array and datagrid Pin
Otex30-Apr-09 22:52
Otex30-Apr-09 22:52 
AnswerRe: load settings.settings in an array and datagrid Pin
DaveyM691-May-09 0:13
professionalDaveyM691-May-09 0:13 
GeneralRe: load settings.settings in an array and datagrid Pin
Otex1-May-09 0:36
Otex1-May-09 0:36 
QuestionHow can I create a DataView based on several DataTables? Pin
maoz30-Apr-09 22:32
maoz30-Apr-09 22:32 
AnswerRe: How can I create a DataView based on several DataTables? Pin
Henry Minute1-May-09 1:03
Henry Minute1-May-09 1:03 
QuestionSql Problem!! Pin
Nafiseh Salmani30-Apr-09 21:56
Nafiseh Salmani30-Apr-09 21:56 
AnswerRe: Sql Problem!! Pin
Abhijit Jana30-Apr-09 22:51
professionalAbhijit Jana30-Apr-09 22:51 
AnswerRe: Sql Problem!! Pin
fly90430-Apr-09 23:21
fly90430-Apr-09 23:21 
QuestionString to Dataset? Pin
nabilg30-Apr-09 21:28
nabilg30-Apr-09 21:28 
AnswerRe: String to Dataset? Pin
HuntingWabbits30-Apr-09 23:28
HuntingWabbits30-Apr-09 23:28 
AnswerRe: String to Dataset? Pin
Mycroft Holmes1-May-09 2:21
professionalMycroft Holmes1-May-09 2:21 
QuestionGreat NMS tool Pin
gvgohome30-Apr-09 16:50
gvgohome30-Apr-09 16:50 
AnswerRe: Great NMS tool Pin
Christian Graus30-Apr-09 19:14
protectorChristian Graus30-Apr-09 19:14 
QuestionAsk about table in C#? Pin
Johnscorta30-Apr-09 15:58
Johnscorta30-Apr-09 15:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.