我制作了一个小程序,它将从网站更新字符串的值并将其放入文本框中。我想我已经接近完成了,但我不确定我怎么能让它重复,我有几个错误
程序不包含静态' Main'适用于入口点的方法
' Form1.textBox1'由于其保护级别而无法访问。
- 我知道我可以通过删除异步修复静态主要问题(即使它是静态的),但是我怎么能实现一个循环?
- 是什么让textBox 1无法访问,我该如何解决?它是一个单独的.cs文件,包含在项目中
namespace WindowsFormsApp2
{
static class Program
{
static async void Main() // program does not contain a static Main method??
{
Form1 Buttons = new Form1();
HttpClient client = new HttpClient();
try
{
MatchCollection matches;
HttpResponseMessage response = await client.GetAsync("https://www.coinbase.com/api/v2/prices/USD/spot?");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
string pattern = "BTC\",\"currency\":\"USD\",\"amount\":\"([^\"]*)";
Regex responsex = new Regex(pattern);
matches = responsex.Matches(responseBody);
Thread.Sleep(100);
Buttons.textBox1.Text = matches; // Form1.textBox1 is inaccessible due to its protection level
}
catch (HttpRequestException)
{
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public bool Play;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Play = !Play;
if (Play == true)
{
button1.Text = "Pause";
}
else
{
button1.Text = "Resume";
}
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}