Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI, I have a question about an asynchronous method. How to get the result value in class A after the value changed in class B.

My code :

C#
public class A
{

}


public classe B
{
   String result;
   private void OnDataAvailable(object sender, DataAvailableEventArgs e)
        {
            ...
            result = e.Data;
        }


}

Think you !
}
Posted
Updated 10-Jun-11 8:06am
v2
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 14:41pm    
What you want is not asynchronous. Griff provided a good solutiom. Also, always prefer threads to asynchronous methods (when you learn what is asynchronous, perhaps).
--SA

If you're using .Net 3.5 or newer, you could make Class B an Observable object (derive from IObservable), and then make Class A handle Class B's NotifyPropertyChanged event.

If you're using .Net 3.0 or older, you could have Class A handle Class B's OnDataAvailable event (or a custom event that reflects it AFTER Class B's data has been set).
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 14:42pm    
5. See also my comment to the question above.
--SA
yesotaso 10-Jun-11 14:57pm    
Sorry for intrusion but isn't IObservable<t> Interface unavailable at .Net 3.5?
#realJSOP 10-Jun-11 15:16pm    
It is available - you can do WPF with 3.5, so you can use IObservable...
yesotaso 10-Jun-11 15:52pm    
Thank you for the info and apologies for uninformed deviation from the subject.
This article[^] discusses various asynchronous return patters and should be very useful to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900