You are viewing limited content. For full access, please sign in.

Question

Question

Search.Run vs. Search.BeginRun methods RA SDK

asked on August 10, 2016 Show version history

In the SearchClientApp.cs sample included with the SDK samples you have the following code to execute the search...

LongOperation longOp = search.BeginRun(false);
while (!longOp.IsCompleted)
{
    Thread.Sleep(1000);
    search.UpdateStatus();
}

Is there an advantage of using the BeginRun instead of the Run method?  

When would you choose to use one over the other?

Why manually write the "wait state" code when you can pass true into the BeginRun method?

0 0

Answer

SELECTED ANSWER
replied on August 10, 2016

The only reason to call BeginRun(false) is if you want to have a chance to cancel the operation. Calling Run() or BeginRun(true) will block on the LFS side (instead of blocking on the client side like in the code), so this sample code is not very useful.

1 0
replied on August 10, 2016 Show version history

Thanks Robert,

I have found much of the sample code to be lacking in best practices.  Seems the developers creating the sample code did not understand best practices.  I understand it is sample code but we use this code to learn from and we will learn very bad habits from it. 

A prime example is that much of the sample code does not use the using clause when creating a session (including SearchClientApp.cs).  Wonder how many developers out there are doing the same thing in their production code because they are using the sample code to learn from!

0 0
replied on August 10, 2016

Thanks for pointing this out, we will look into fixing it.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.