Hi There,
I am trying to integrate splunk into a windows forms application. the code goes into eternal wait mode at this line. No execution occurs after this line. Can you please lookinto the code and let me know if I am missing out on something? I am using splunk-sdk-csharp-pcl sdk from your site.
// On a button click event I am calling the method search().
private void btnSearch_Click(object sender, EventArgs e)
{
search();
}
public void search()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using (var service = new Service(SdkHelper.Splunk.Scheme, SdkHelper.Splunk.Host, SdkHelper.Splunk.Port, new Namespace(user: "nobody", app: "search")))
{
Run(service).Wait();
}
}
static async Task Run(Service service)
{
//await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password);
//// Search : Pull model (foreach loop => IEnumerable)
Job job = await service.Jobs.CreateAsync("search index=_internal | head 10"); // **EXECUTION STOPS HERE**
SearchResultStream stream;
using (stream = await job.GetSearchResultsAsync())
{
try
{
foreach (SearchResult result in stream)
{
MessageBox.Show(string.Format("{0:D8}: {1}", stream.ReadCount, result));
}
MessageBox.Show("End of search results");
}
catch (Exception e)
{
MessageBox.Show(string.Format("SearchResults error: {0}", e.Message));
}
}
//// Search : Push model (by way of subscription to search result records => IObservable)
job = await service.Jobs.CreateAsync("search index=_internal | head 10");
using (stream = await job.GetSearchResultsAsync())
{
var manualResetEvent = new ManualResetEvent(true);
stream.Subscribe(new Observer<SearchResult>(
onNext: (result) =>
{
Console.WriteLine(string.Format("{0:D8}: {1}", stream.ReadCount, result));
},
onError: (e) =>
{
Console.WriteLine(string.Format("SearchResults error: {0}", e.Message));
manualResetEvent.Set();
},
onCompleted: () =>
{
Console.WriteLine("End of search results");
manualResetEvent.Set();
}));
manualResetEvent.Reset();
manualResetEvent.WaitOne();
}
}