ここでC#の初心者を完了しますので、たるみを減らしてください。
私はトレイに住むこのアプリケーションを持っています。トレイをクリックすると、「設定」フォームにアクセスします。これはすべてコード化され、機能しています。
ただし、このアプリの主な機能は、node.jsで記述されたアプリケーションに接続し、実行することをポーリングし続けることです。
これもコード化されて機能していますが、(恐ろしい)警告があります。
メインクラスはこれを行います:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form = new Form1();
ApplicationContext applicationContext = new ApplicationContext();
applicationContext.MainForm = form;
Application.Run(applicationContext);
}
}
フォームを非表示にして実行するため。そして、メインのアプリサイクルは、Loadイベントの形式で行われます。
private void Form1_Load(object sender, EventArgs e)
{
string basePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"ArchSync"
);
if (!Directory.Exists(basePath)) {
Directory.CreateDirectory(basePath);
}
WebClient client = new WebClient();
Int64 timestamp = 0;
while (true)
{
// main app loop
}
}
言うまでもなく、このアプリケーションは機能しますが、メインスレッドがHTTPインタラクションを実行するのに忙しいため、トレイアイコンは何もしません。
UIスレッドの外部でメインアプリケーションループを実行する正しい方法は何ですか?
ありがとう!