0

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.

Secret Secret
  • 77
  • 1
  • 8
  • Why not just use task continuation and go ahead? – Sriram Sakthivel Nov 03 '13 at 10:52
  • 1
    Use the Task Parallel Library? (http://msdn.microsoft.com/en-us/library/dd537609.aspx) `async` and `await` are handy, but they're not the first asynchronous model in the language. Going back as far as .NET 1 you can perform multi-threated tasks, the implementation is just bulkier the further back you go. Or, if you don't need it to be asynchronous, you can just remove the `async` and `await` calls from the implementation entirely. (Probably won't be a great UX in that case, though.) – David Nov 03 '13 at 10:55
  • Can't this be achieved with `Jquery UI auto-complete`? – Christian Phillips Nov 03 '13 at 10:56
  • @christiandev: Perhaps, if it's a web application. But there's no indication of that here. The sample code is a console application, for example. – David Nov 03 '13 at 11:06
  • Using Task Parallel Library seems to be what I need. David, if possible can you explain how I can use it to implement this: http://martinnormark.com/google-search-suggestions-api-csharp/ If its time consuming, just give me some pointers. Also post it as Answer, I will mark it as Answer. Thanks! – Secret Secret Nov 03 '13 at 11:10

1 Answers1

2

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.

David
  • 208,112
  • 36
  • 198
  • 279