Search code examples
c#.netwindowsservicesystray

.net - how to connect windows service with systray application


I have a windows service that do something periodically. on user account runs systray application (written in C#) that communicate with windows service (thru .net remoting) and shows a status and some option to users.

Everything works well beside that systray app uses 20-30MB of RAM ! it have to work in terminal environment, when 50 users login, only systray apps take >1GB of RAM ! and i don't have to add, that's wrong :)

Is it possible to write .net systray application that will be small ? (1-2MB max?) or should I write it in c/c++? then, what kind of communication should I use between windows service (written in C#) and systray app ?


Solution

  • I've added following line to my code (app calls it sometimes along with GC.Collect() )

    System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet =
                    System.Diagnostics.Process.GetCurrentProcess().MinWorkingSet;
    

    Memory usage dropped to ~2MB (from 15-25MB), after nulling some objects after use (drawing menu and icon), memory usage dropped to ~540KB ! it grows a little (to ~2-3MB if I use context menu, but then it drops back to ~540KB)

    So, goal achieved :)