Different window class name - c#

I have a problem with a window class name, which I get by window's Win32 method - GetClassName.
My application is in .NET, C#. When I run my application for the first time, the class name is WindowsForms10.Window.8.app.0.2dac507_r13_ad1. Then I close the application and my settings are saved in user.config (it's very important). When I run application for the second time, the class name is WindowsForms10.Window.8.app.0.338574f_r13_ad1. Then I close the application and run it again, the class name will be always the same. But when I restart my PC, the process is repeated, it means that the class name as when the application is run for the first time. Why ? Why isn't the class name the same every time I run the application?
I need it to get a window of another application. I'm trying to get it by the method FindWindow. It is true that we can use the title of the window for this method, but I need a class name, too.
It is important to mention that in case of other applications, which do not save settings, the class name is always the same, after each execution.
So, where is the problem ?
Thank you.

Related

Opening WPF Window from another Window

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.

Running Projects Programmatically

I was wondering if it is possible to open a second project (in the same solution as the first one) by code in the first project.
For example i have one form application project and another console application project.
The form application starts and when the user clicks a button i want the console application to run and the form application to stop.
Or could someone tell me how to delete my application .exe file?
The projects don't need to be in the same solution to do that. Just use Process.Start to start the executable for another application, and then close the main form to end the current application.
If you don't want to run the code as an entirely different process then it may also make sense to have a 3rd project that is a "class library" that the other two projects could add a reference to. This would allow you to define common code used in either application, using classes that are generalized to be helpful in either project.
I'm not sure what you're trying to do; but Process class has Start and Kill methods that will let you launch / exit processes.
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

How can I run an application and do not show the console?

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.

Run code after form load periodically

I am developing a desktop window application. After form load, get some data from running machine and saved it to the ftp server in csv file and it shows that test completed. I want to run the same code which takes values and store on the sever after every one hour. How can i do it?
Console application and window service is not feasible solution because I have to show the form to the user etc.
Use one of the timer classes that come with the BCL.
See Comparing the Timer Classes in the .NET Framework Class Library on MSDN.
Essentially you setup a timer with an interval (how often to fire, in your case every hour) and with a method to execute when it fires.

How to Run program one Process and some name only?

i create some project but when start App. How to Run this App one Process only and name much "test.exe" name only? when Lunch APP ? C# 2.0
Here's a sample project which looks promising:
http://www.codeproject.com/KB/cs/SingleInstanceAppMutex.aspx
I quote the goals here:
Goal #1: Prevent a Second Instance
from Opening
Goal #2: Activate the First Instance
Goal #3. If the First Instance is
Minimized to the System Tray (aka
"Notification Area"), Restore It
Again, not entirely sure what it is you are going for, but my interpretation:
If you want to ensure that only a single instance of your process is ever running at once, insert the following code at the beginning of your main method (in Program.cs).
if (Process.GetProcessesByName (Process.GetCurrentProcess().ProcessName).Length > 1)
{
//instance of the process already active, exit
return;
}
You will need to include using System.Diagnostics at the top of your file.
Note that this is not a perfect solution, in that if a user starts two instances of the process at exactly the same time, then they will both probably close.

Categories

Resources