【发布时间】:2018-02-03 04:10:42
【问题描述】:
我正在尝试获取它,以便在我的循环进行时,程序仍将运行,我尝试使用 async/await 组合但没有成功。我应该怎么做才能让程序在循环同时运行时顺利运行?
Btc 值被发送到一个标签,该标签会更新该值是什么
namespace WindowsFormsApp1
{
public static class Program
{
public static string Btc;
public static void SendRequest()
{
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://api.coinbase.com/v2/prices/USD/spot?");
using (var response = req.GetResponse())
while (true)
{
var html = new StreamReader(response.GetResponseStream()).ReadToEnd();
Btc = Regex.Match(html, "\"BTC\",\"currency\":\"USD\",\"amount\":\"([^ \"]*)\"}").ToString();
Thread.Sleep(300);
}
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
SendRequest();
}
}
}
【问题讨论】:
-
将
async方法修饰符和await运算符与ReadToEndAsync等方法一起使用
标签: c# asynchronous