背景工作者只在最后工作

时间:2016-12-01 22:25:59

标签: c#

我有一个按钮事件执行以下操作:

Available = true
while (Available)
{
    var cclient = new RestClient("http://192.168.1.1:1234/api/customers");
    Log.log("http://192.168.1.1:1234/api/grab/customers");
    var crequest = new RestRequest(Method.GET);
    request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
    request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"\"\r\n\r\n\r\n-----011000010111000001101001--", ParameterType.RequestBody);
    IRestResponse cresponse = client.Execute(crequest);
    Log.log(cresponse.StatusCode.ToString());
    if (cresponse.StatusCode.ToString() == "OK")
    {
        List<Rate> result = JsonConvert.DeserializeObject<List<Rate>>(cresponse.Content);
        var groupedData = from b in result.AsEnumerable()
                          group b by b.First_Name into g
                          select new
                          {
                              First_Name = g.Key,
                              //Count = g.Count(),
                              Qty = g.Sum(x => x.Qty)
                          };
        foreach (var x in groupedData)
        {
            Log.log(x.First_Name + " " + x.Qty.ToString());
        }
    }
    WaitSeconds(); //this waits 2 seconds to give it enough time to write to the log file
}

while循环正在发生......但它并不像我期望的那样每两秒记录一次数据。

我有一个按钮,使其可用,然后记录数据。

我尝试将其放入后台工作程序,但仍然不记录数据。

我不确定为什么。

谢谢,

1 个答案:

答案 0 :(得分:-1)

我能够通过添加以下内容来解决这个问题:

Button

现在我得到了一致的记录。