我试图从Windows服务的OnStart()方法调用以下方法,但是Windows服务启动和停止并抛出错误。
static async Task RunAsync()
{
LightSpeedContext<RightHireUnitOfWork> _context;
var client = new HttpClient();
_context = new LightSpeedContext<RightHireUnitOfWork>("default");
client.BaseAddress = new Uri("https://api.xyz.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.TryAddWithoutValidation(
"X-SmartToken",
"1dfaaad541c45031c8b92bfab3ssssssssssb5644c368f3");
var content = new StringContent("", Encoding.UTF8,
"application/json");
string config = "v1/assessments?status=NEW";
HttpResponseMessage response = null;
try
{
response = await client.GetAsync(config);
}
catch (HttpRequestException httpEx)
{
// determine error here by inspecting httpEx.Message
}
if (response.IsSuccessStatusCode)
{
ListResult lr = await response.Content.ReadAsAsync<ListResult>();
List<SmartRecruiters.AssessmentOrder> lAsmtOrders = lr.content;
//在此进行其他处理
}
}
OnStart方法如下:
protected override void OnStart(string[] args)
{
this.WriteToFile("Simple Service started {0}");
// Need to call the RunAsync method here...
}
我尝试使OnStart异步,但它没有帮助。有关如何成功拨打电话的任何想法?