Error 1 The name 'manualResetEvent' does not exist in the current context
Error 2 Cannot await 'Splunk.Client.SearchResultStream'
Error 3 The name 'manualResetEvent' does not exist in the current context
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Net;
using Splunk.Client;
using Splunk.Client.Helpers;
namespace Test
{
public class Class1
{
static void Main(string[] args)
{
//Service Point Manager for non-production splunk local instance
#region
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
{
return true;
};
#endregion
//Creates service instance for methods to log into with scheme, host, and port arguments
using (var service = new Service(Scheme.Https, "localhost", 8089))
{
RunNormalSearches(service).Wait();
}
}
//Normal Search Pull Model
static async Task RunNormalSearches(Service service)
{
await service.LogOnAsync("admin", "CsIt30!q");
Job job = await service.Jobs.CreateAsync("search index=_internal | head 10");
SearchResultStream stream;
using (stream = await job.GetSearchResultsAsync())
{
try
{
foreach (SearchResult result in stream)
{
Console.WriteLine(string.Format("{0:D8}: {1}", stream.ReadCount, result));
}
Console.WriteLine("End of search results");
}
catch (Exception e)
{
Console.WriteLine(string.Format("SearchResults error: {0}", e.Message));
}
}
Console.ReadLine();
using (stream = await job.GetSearchResultsAsync())
{
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();
}));
await stream; // wait for stream to complete
}
}//EndOfAsyncRunNormalSearches
}//EndOfClass1
}//EndOfNamespace
Hi zd00191
Sorry you are having issues. You are getting a compilation error because manualResetEvent is not defined in that code snippet.
You can add the following code after line 60 and it should work:
var manualResetEvent = new ManualResetEvent(true);
I'll talk to our docs folks and get the code updated.
I see why. You cannot use await from a void method which is where you put your code ie in the main method.
Put your code in a method that returns a Task and then invoke it.
See how we did it here: https://github.com/splunk/splunk-sdk-csharp-pcl/blob/master/examples/normal-search/Program.cs
I get an error under line 61 when I insert the new line of code
What error?
Can you send me a gist showing the exact code with the line added?
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();
}));
await stream; // wait for stream to complete
}
And the error?
Error 1 Cannot await 'Splunk.Client.SearchResultStream'
Do provide the URL where you got the code from.
What host are you trying to access? Localhost or somewhere else? Line 24
Do you get an error message when you try to use this class?
local host
I installed a free splunk enterprise instance this morning and added the sample tutorial data
These are the errors:
Error 1 The name 'manualResetEvent' does not exist in the current context
Error 2 Cannot await 'Splunk.Client.SearchResultStream'
Error 3 The name 'manualResetEvent' does not exist in the current context
Line 69, Line 74, Line 77 are where the errors are