I am have two different WPF applications running differently. now my requirement is to merge these application. Now Both application are WPF application. So I need to call Second application from the First Application So bascially I have created Two windows and I am initializing the Window2 from Window1 on a button click. Now the problem assuming that I have used the same resource files for both application.
What will happen if I close my First WPF application will the Second application will also get closed?
What should be the best approach in these situations?
If my main application window closes then the resource will also go out of scope and how should i ensure my appliction works correctly?
At the Application level you can set the ShutdownMode property to define the condition that will make the application terminate.
If the second application cannot run without the first one for some reason, as you suggest in your post, you could set this property to OnMainWindowClose. This way, if the first one is closed, the full application will stop
Spawn a new process on button click, that opens AppB. But that will keep both apps separate from each other, so no data sharing either. If you want to share data and code, add each page from AppB manually to AppA just like adding a third party control.
Related
I created app that open every time that I start pc. So its so annoying to close it every time so I'm wondering if its some code that will hide my console app. I saw videos and tutorials on forms but idk how to do it with console app.
The easiest way to do this is change your console app to a windows app.
Console apps get a console made for them by Windows. But if you change it to a windows forms app, then windows expect the application to make a window, so if you never make a window, then it will never show
The other way is to turn your application into a service. This has some additional requirements in terms of programming
Option 1
You can use this run command:
start /min "SomeTitle" MyConsoleApp.exe myarg1 myarg2
Thus it will be on the taskbar minimized.
Option 2
If you use a file link in the start menu, select the start minimized option for the exe.
Option 3
Using a WinForm app you will be able to use a tray icon by setting the main form as not visible, to say it simply because it can be complex according to the expected behavior, and it will not be in the taskbar too.
Option 4
If you don't want a main form, create a win form app, delete the form file and the code in the main method, and you're done, without GUI nor console, no main input and no main output but you can show MessageBox and some forms when necessary, just a background process only visible in the Task Manager.
With that you can add a tray icon to to offer exit and some status information for example.
Option 5
Also you can create a windows service:
.NET console application as Windows service
Note
In all cases, if you don't use an internal message events dispatcher like the WinForms Application pattern or WPF and so on, be carefull to not saturate the CPU with the processings like with loops and use Thread.Sleep() between iterations or any thread idleing pattern or some timer if necessary.
I have two WPF Applications, for example, one is A_wpf application, the others is B_wpf application.
There are one Button on each application. I want to Button in A_wpf application to Start up B_wpf application and show B_wpf with Maximized. I want to Button in B_wpf application to do the same thing as A_wpf Application do.
Could anyone give me any advices please?
You can use Process.Start(path_to_exe):
using System.Diagnostics;
//...
Process.Start(path_to_exe);
Now if you want to avoid opening another instance if the target application is already running, you coud use Mutex for that.
I am designing an app which basically is going to check for new data, my initial thought for this is to use a windows service. If i get any new data i need to display a winforms app which i'll populate with this data so that the user can acknowledge it.
I know there are restrictions running UI apps from a service so i'm just wondering what others believe is the best approach for both. Also i need to run this on XP
The timer that gets the data
how to launch the WinForms App
As im writing this i've also been toying with the idea of using a console app but nothing seems to be fitting together in terms of functionality.
You can use a regular Winforms app. As soon as the application loads, hide the entry form from within the Form_Load method, this will keep the form hidden from the user. Keep a timer on the entry form that frequently checks for relevant data and pops up windows as and when required.
I've got a console application and I want to run it from another application. But when I invoke it from code--to call program I use ActiveXObject--it shows the console. How do I get it to not show the console? I mean, the program works but console is shown.
If you make the application a Windows Application instead of a Console Application it will not show or open (or use) a Console. Your code can stay the same - and the application will still function (without ever creating a Form or Window).
That being said, if you control the "other" application, you may want to consider making a class library instead of a separate Application. This would allow you to just include and run code within the library without starting a separate process.
You can create it as a Windows Forms application with a hidden window. That's just one possibility like Reed Copsey pointed out, i used it once because i needed to process some specific Window Messages.
I'm having a bit of a trouble trying to create a multi window'ed console application. Currently, my application's main console window is used to collect user input and display output.
Much of this output comes from a separate thread, as live data comes in. I was wondering if there is a way for me to separate my application into two windows, where the second window was either a console window or even any other kind of window that could display the text of the incoming strings... In particular, the main console window would be where the user input commands etc, and the second window displayed what the system was currently working on. This second window could be entirely readonly.
Any suggestions would be greatly appreciated! I would post code, but I don't really have anything relevant (that I can think of) to post....
This will be hard to do.
Here is answer for similar question: Can you have multiple .net Consoles (as in Console.Writeline)
If you really want to do it, you can find logic here: http://www.codeproject.com/KB/cpp/MultipleConsoles.aspx
Maby better approach will be to start another process (console app) and communicate between them thru IPC ( Interprocess communication ) - like named pipes .
More about IPC you can find: http://www.infoq.com/news/2008/01/wcf-comm-options
It is probably easier to just pop-up a Windows Form with a TextBox containing the data you wish to show. You can simply start a new thread and call Form.ShowDialog() to get the form to show.