WCF Web服务在While循环

时间:2016-03-11 13:26:23

标签: c# wcf while-loop crash client

我正在创建一个WCF客户端,其中包含一个带有计时器的while循环,只要没有按下停止按钮,就会每隔x秒从Web服务获取一个priceata并发送pricingata。相关代码如下所示:

// Starts the while loop
private void StartButton_Click(object sender, EventArgs e)
{
    Stopped = false; 
    // The Indicator is green when on and red when off.
    Indicator.BackColor = System.Drawing.Color.DarkSeaGreen;
    Table.DataSource = client.GetPrices().ToList();

    while (!Stopped)
    {
        string content = File.ReadAllText(directory + filename);
        client.SendPrices(content);
        System.Threading.Thread.Sleep(1000); 
        Table.DataSource = client.GetPrices().ToList();
        System.Threading.Thread.Sleep(1000);
    } 
}

// Stops the while loop
private void StopButton_Click(object sender, EventArgs e)
{
    Indicator.BackColor = Color.Red;
    Stopped = true; 
} 

问题是代码正常编译并且没有显示警告,但是在按下开始按钮后,while循环崩溃了。这段代码出了什么问题?

0 个答案:

没有答案