質問

I am trying to implement this: http://martinnormark.com/google-search-suggestions-api-csharp/

I am using c# express and I don't have visual studio 2010 SP1, because of that I am unable to use Asynchronous Programming with Async and Await.

Is there an alternate way for me to implement Google Search suggestion API?

In my project, I need to get related terms from internet for key terms provided by the user. I decided to use Google search suggest for that, but I am stuck now. Any help would be appreciated.

Thanks in advance.

役に立ちましたか?

解決

You can potentially still use the Task Parallel Library for your asynchronous tasks. Without going into too much implementation detail here, let's say you have a couple of method signatures which break apart the functionality into discrete components:

void FetchGoogleSearchResults(searchString);
void DisplayGoogleSearchResults(results);

The first method would internally call the second. There's nothing inherently asynchronous about either of these methods in how they're defined/implemented. They're normal methods which can even be called synchronously like any other if you'd like.

Then you might perform the first method asynchronously, where the second method sort of acts as its callback when it's complete. (Which it doesn't do asynchronously, just as the last thing it does in its thread.) You might invoke the first method like this:

Task.Run(() => FetchGoogleSearchResults("some search string"));

That should fork off a thread for the fetching of the Google results (which is the bottleneck, so that's what should be in the thread), and that thread will display the results when it's completed.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top