Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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;
    // doing some initial stuff, ia a few times CSM.items.Add(...) -- no problem 'till here
    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 !
Posted
Comments
Sergey Alexandrovich Kryukov 17-Jan-14 19:10pm    
InvokeRequired returns false when and only when it is called in the same thread as the thread where the UI was started, with the control calling InvokeRequred being a part of the same UI. The issue of thread is totally orthogonal to the AppDomains. I don't see how you problem can possibly be related to AppDomain.
—SA
Alex M.H. 18-Jan-14 2:44am    
thx for your answer - of course, you are right !!! (If someone's running out of logical conclusions ...) I don't deal with threads in the current project.

Nevertheless I'm clueless about what went wrong. It's a simple string that I add to my CMS .
And: before Application.Run() it works.
Any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900