czubehead
czubehead

Reputation: 552

tell the same .net app that it's already running

I have a WPF app that I launch when the computer starts up with hidden window, so it works like a background task. It sometimes syncs with a certain website and when it finds out that there is some new date it shows a popup window. User should also can show a standard GUI in a way he would start a new app. I can detect by Mutex in the new app that it's new and I don't want it and will shut it down, but I've no idea to tell the older app that is should show GUI. Any idea how to do this? I don't need to post some string or something like that I just need to do a certain method in the older app.

Upvotes: 0

Views: 52

Answers (1)

Jon
Jon

Reputation: 3255

You can send it a Windows Message using this API call. Then in the hidden background app, you can check for this message, and show your UI:

[DllImport("User32.dll")]
public static extern Int32 SendMessage(int hWnd, int Msg, int wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);

Here in your background app form, override the WndProc handler:

protected override void WndProc(ref Message msg)
    {
        // filter messages here for your purposes
        if (msg.wParam = MY_MESSAGE_CONSTANT) { ShowUI(); } 
        base.WndProc(ref msg);
    }

Another way to do this would be to use a FileSystemWatcher object, and watch a folder on your disk somewhere. The first app could create a file there, and your background app would be notified and could show it's UI.

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

Upvotes: 1

Related Questions