Well, maybe im just to tired to see the tree ...
I'v written a tray-app, which includes a WinForm with a NotifyIcon (on it). There's also a ContextMenuStrip CMS connected to the NotifyIcon's contextmenustrip-property.
I did the main method the following way:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SomeForm TrayForm = new SomeForm();
TrayForm.WindowState = FormWindowState.Normal;
TrayForm.Visible = false;
TrayForm.ShowInTaskbar = false;
TrayForm.FirstRun();
Application.Run();
}
BUT I've a method in the TrayForm class that is triggered by an event (works!) and should add one more item to the CMS.
Right here the problem occures: CSM.Items.Add(...) is executed, but the method is aborted immediatly -
the code behind that statement will never be executed.
The only explenation that I have for that strange behaviour, is that starting the Programm with
Application.Run();
leads to a different appdomain and so the GUI-stuff executed after Application.Run() is not in reach for the TrayForm instance, that was created before that statement.
I'v also checked the other way round
Application.Run(TrayForm);
and everythig's fine. But then I'm in trouble with hiding the WinForm.
On the other hand, extending my event-triggering method with
if (Invoke.Required) ...
fails, because Invoke.Required always returns false !
Anyone out there with a chain saw ?? :-) :-)
thx a lot !