本文整理汇总了C#中Job.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Job.GetAsync方法的具体用法?C# Job.GetAsync怎么用?C# Job.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job.GetAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetJobAsync
/// <summary>
/// Asynchronously retrieves information about a search job.
/// </summary>
/// <param name="searchId">
/// ID of a search job.
/// </param>
/// <remarks>
/// This method uses the <a href="http://goo.gl/SFqSPI">GET
/// search/jobs/{search_id}</a> endpoint to get the <see cref="Job"/>
/// identified by identified by <see cref="searchId"/>.
/// </remarks>
public async Task<Job> GetJobAsync(string searchId)
{
var resource = new Job(this.Context, this.Namespace, searchId);
await resource.GetAsync();
return resource;
}
示例2: CreateJobAsync
/// <summary>
/// Asynchronously starts a new search <see cref="Job"/>.
/// </summary>
/// <param name="args">
/// Specification of a search job.
/// </param>
/// <returns>
/// An object representing the search job that was started.
/// </returns>
/// <remarks>
/// This method uses the <a href="http://goo.gl/JZcPEb">POST
/// search/jobs</a> endpoint to start a new search <see cref="Job"/> as
/// specified by <see cref="args"/>.
/// </remarks>
public async Task<Job> CreateJobAsync(JobArgs args)
{
Contract.Requires<ArgumentNullException>(args != null, "args");
Contract.Requires<ArgumentNullException>(args.Search != null, "args.Search");
Contract.Requires<ArgumentException>(args.ExecutionMode != ExecutionMode.Oneshot, "args.ExecutionMode: ExecutionMode.Oneshot");
// FJR: Also check that it's not export, which also won't return a job.
// DSN: JobArgs does not include SearchExportArgs
string searchId;
using (var response = await this.Context.PostAsync(this.Namespace, JobCollection.ClassResourceName, args))
{
await response.EnsureStatusCodeAsync(HttpStatusCode.Created);
searchId = await response.XmlReader.ReadResponseElementAsync("sid");
}
// FJR: Jobs need to be handled a little more delicately. Let's talk about the patterns here.
// In the other SDKs, we've been doing functions to wait for ready and for done. Async means
// that we can probably make that a little slicker, but let's talk about how.
Job job = new Job(this.Context, this.Namespace, name: searchId);
await job.GetAsync();
return job;
}
示例3: Wait
/// <summary>
/// Wait for the given job to complete
/// </summary>
/// <param name="job">The job</param>
/// <returns>The same job</returns>
public Job Wait(Job job)
{
while (!job.IsDone)
{
Thread.Sleep(1000);
job.GetAsync().Wait();
}
return job;
}