私の問題は、バックグラウンド アプリケーションを作成したいが、システム トレイに復元して最小化できるユーザー インターフェイスを使用し、Windows で起動することです。起動方法を検索してみましたが、UI のない Windows サービスに関するスレッドや、フォームを作成して非表示にするスレッドしか見つかりませんでした。だから私の質問は、どうやって始めればいいですか?Windows フォーム ? サービスと何らかの形でインターフェースを追加しますか?
ありがとうございました!
私の問題は、バックグラウンド アプリケーションを作成したいが、システム トレイに復元して最小化できるユーザー インターフェイスを使用し、Windows で起動することです。起動方法を検索してみましたが、UI のない Windows サービスに関するスレッドや、フォームを作成して非表示にするスレッドしか見つかりませんでした。だから私の質問は、どうやって始めればいいですか?Windows フォーム ? サービスと何らかの形でインターフェースを追加しますか?
ありがとうございました!
ユーザーがログインしたときにアプリケーションを起動したい場合は、フォームを作成して非表示にする方法があります。
ユーザーがログインしていなくてもコードを実行したい場合は、Windows サービスが必要になります。
その道を進むことを選択した場合、何らかの形でサービスと対話するアプリケーションが必要になる可能性が高くなります。
フォームに関連付けられていないアプリを作成する方法を次に示します。標準の WinForms プロジェクトを使用しますが、ApplicationContextのカスタム実装を次のように渡しますApplication.Run()
。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyContext());
}
}
public class MyContext : ApplicationContext
{
public MyContext()
{
// this is the new "entry point" for your application
// use Application.Exit() to shut down the application
// you can still create and display a NotifyIcon control via code for display in the tray
// (the icon for the NotifyIcon can be an embedded resource)
// you can also display forms as usual when necessary
}
}