c# how to open form from running application - c#

I'm creating an application that should always be running in the system tray.
This is working like a charm.
now when I open the application for a second time, i have used the Mutex method and now also the Process.getprocessesbyname method.
im able to find if there is already an instance running. im killing that process and start a new one. this is oke, but when I check the systemtray the old icons stay...
is there a way to find the running application and if it is running just show the form from that application instead of the new form.
when you now close the application with the X its not in the taskbar anymore only in the systemtray.
thx !

Related

How to implement to restore the last saved or opened instance or page for a windows application in case of crashed?

I wanted to implement one of my idea where I want to restore or open the saved pages again of the last instance for a window application in case of crashed or sudden shut down.
The current approach, as we have to re-configured all the steps and actions as we have done before crashing.
Background - We have a WPF windows application with C# and legacy code.
Suggest me any suggestion or way to achieve this.

Run a program as a process in the background

I want to create a program that won't close when you click the close button but, only when a exit function is run from within the form.I was thinking i could have it run in the background without the window needing to be open (Like the steam client and dropbox, mediafire, google drive, google chrome extension notification), and was wondering how to do that.
I was thinking of some ways to do it but i wasn't sure how to do them:
A starter program that keeps it open in the background
Running a background process that keeps information stored
I am running c# 2010 so i will need answers relating to that. I would also prefer to not use 3rd party extensions/tools except a basic text editor(Notepad++).Thank you in advance!
There are a number of possible options:
Hide the main form
Create a Tray application
Write a Windows Service

How to keep process running after closing the program?

I am now developing an application on Windows Mobile 6.5 with .Net Compact Framework 3.5 using C#. There is a function in the program that I use it to update the location information periodically from server side, but if I keep running this computation, it would cost too much energe. For this reason, I want to run it in background and I try to use BackgroundWorker to do this and it works well.
The problem I have now is that I can't minimize the program so that I have to keep the main form of the program run in foreground even if it's not doing anything and this is very inconvinence for a user. However, when I close the program, the BackgroundWorker will also be closed.
Is there any method to keep the update process running (somewhere in memory or so) when I close the program? and then can restore the information when I restart the program?
How about creating a Service instead of a background worker?
If your Form closes, then Application.Run (probably called over in Program.Main) returns and the process' primary thread exits, causing the application to terminate.
The solution, then, is don't close the Form, simply Hide it. By default the "MinimizeBox" property for your Form should have been true and it should have an [X] in the upper right corner. Clicking this minimizes the Form and will not exit your application.
The other option in some cases is to not have a Form at all. The challenge here is that the CF doesn't have any Application.Run overload that doesn't accept in a Form (like the desktop framework does). The Smart Device Framework does provide one if you want to go that route.
I have not used the .NETCF 3.5. However in the previous version on .NETCF 1.0/2.0 I observed that even if you close the application using (X) button, it just goes to background but remain in the memory.
If that is the case with .NETCF 3.5 as well then I think you do not need to anything here. The background worked will be running even if you close the application.
I Hope this will help you.

C# windows application not closing

I have a C# windows application. I placed it on a test server, whose set up is not controlled by my company and neither is the seurity context. I double click the exe. App runs and i see my form. I close the application, i open task manager and i still see a foot print of the applicatiion.
taskkill does not seem to remove it and it is still running in task manager.
how do i check if any resource is still being held?
The likely cause is that a background thread is still running after your application is closed. Depending on your framework and application configuration a background thread can cause a process to keep running even after the main window is closed.
Do you have any threads in your process? If so make sure to close them out when the main application window is closing. A good place to do this is in the OnClosing method of a Windows Form
Abusing Application.DoEvents() is another way to get into this kind of trouble. If you cannot kill the .exe from TaskMgr, your app is stuck waiting for a driver to finish an I/O request.

Windows Mobile App will not run more than once

I'm having problems getting an application I wrote for Windows Mobile 6.0 to run more than one time on my smart phone.
I built it into a .cab and it installs and runs fine the first time, but if I close the application and try to start it again, it will not run unless I restart the phone.
I have checked the task manager after closing the application and it does not show up.
Are you sure that you are closing your application properly? I recommend using a process manager to see if your application still runs on the background.
My problem was in not handling closing the main Form when the application exited from one of the other forms. Ex: application starts with calculator loaded, user loads unit conversion form from calculator form, and the app hides the calculator. User then closes the unit form and calculator is still running.
All that I missed was handling an OnClosed event in my main form for when the user tried closing the application from one of the other forms.

Categories