完全なC#初心者はこちらですので、少しスラックをカットします。デーモン付き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イベントで行われている:メインスレッドは、HTTPの相互作用をやってビジー状態であるので、言うこと
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
}
}
言うまでもなく、このアプリケーションは動作しますが、トレイアイコンは、何もしません。
UIスレッド外でメインアプリケーションループを実行する正しい方法は何ですか?
ありがとうございます!
ポーリングを行う新しいスレッドを開始します。 – driis