?
Solved

Question regarding asynchronous programming?

Posted on 2009-12-31
2
Medium Priority
?
224 Views
Last Modified: 2013-11-08
I have a function named "Search" which invokes another method "SearchIndividuals" as shown below. In the "SearchIndividuals" it invokes another method "Send" which is defined as asynchronous and as soon as it is done with processing it returns the result using a "callback". In the "SendCallback" method the "Result" variable will be set.

In the "Search" method it needs to process the "Result". How can I make sure it reads the "Result" variable only after it is set in the "SendCallback" method.

Thanks for any help or suggestions.
//class level variable
private string Result = null;

private void Search(object sender, SearchEventArgs args)
{
    SearchIndividuals(Name);

    if(Result! = null)
    //process result

}

private void SearchIndividuals(string name)
{
    AsyncProcess.Send(name);

}

private void SendCallback(object sender, ResponseXml e)
{
    Result = e.Response

}

Open in new window

0
Comment
Question by:ipjyo
2 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 1200 total points
ID: 26154166
u can use while(Result ==null);
ot
put a variable in your class say _CallbackResponseSet which u change to true once SendCallback is done.
something like:

//class level variable
private string Result = null;
bool isDone = false;

private void Search(object sender, SearchEventArgs args)
{
    SearchIndividuals(Name);

    while(isDone == false){
    //process result
}

}

private void SearchIndividuals(string name)
{
    AsyncProcess.Send(name);

}

private void SendCallback(object sender, ResponseXml e)
{
    Result = e.Response
isDone =true;
}
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 800 total points
ID: 26155944
Is this WinForms or WebForms?

Is it ok to BLOCK execution in Search()?
(this could potentially cause an unresponsive WinForm app depending on where this is executing)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question