launch winforms app on schedule - provided conditions are met? - c#

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.

Related

Windows Phone 8 resume/suspend /activated/deactivated

I am currently trying to make an app that takes some data from a server. I have a list and I am populating it when I login with some data. The idea is that that data can change over short periods of time. I made an auto refresh button, works fine, but I wanted to implement something like this:
When you open the app, everything loads, is good (done).
If you minimize (put in taskbar, I don't know how to say, enter on another app or menu). Your app will be suspended. When you resume it, I want it to perform the refresh thing. (Need help).
I'm currently working with Windows Phone 8, started project on this one and want to finish with this one. App.current. doesn't have resume or suspend, which I have found on lots of YouTube videos or on the MSDN site. Therefore I think I should do something with activated / deactivated, but I don't know where to add this handler. On the MSDN site I only found the function.
I am looking for something like this: Event on returning to app, after exiting by Windows key [UWP][Win10 Mobile], but as I told, I don't have this.suspend / this.resume on Windows Phone 8.
If we talk about Windows Phone 8, we have to specify which app flavor is intended.
For Silverlight apps, there are Application_Activated() and Application_Deactivated() methods, usually they're auto-created automatically in the App.xaml.cs
For so called "RT apps" there are events Suspending and Resuming, 1st one is subscribed automatically in the App.xaml.cs (so just put your code into that auto-generated handler), and you have to subscribe to 2nd one by yourself.

Run code once and exit formless app: Windows Forms or WPF... does it matter?

I need to write a very small application which writes some system data to a file and then exits. I could do this in a console application but I have no need or desire for a console window to appear during this process.
I would normally use a Windows Forms application with no forms, execute the code in the Main method and then allow the application to exit, however, this time I couldn't help but wonder if this is the best way to do it and whether you could do it with a WPF application instead, what the differences are and whether or not once you've remove any forms/windows and unnecessary reference, it matters or not.
WPF and WinForms are two different libraries that show UIs.
If you never show a UI, you aren't using either of them.
You should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll.
Alternatively, start with a console project, then change the Output type to Windows Application.
Windows Forms with no window or console app with the type changes to windows application will give you the same result which is a simple app with Main() method and now windows.
WCF will only make sense if you actually want to display something as you're not going to use any of its features in your case.

Noob question - how to create a new windows form as part of a plugin?

I am writing a plugin for a C# application and would like to add a dialog window. I have no control over the application, rather, the application loads plugins dynamically using reflection. I am a newbie with windows forms (this is a forms application) but would like to have a dialog window come up to control my plugin. How can I accomplish this?
If I just add a windows form to my application via visual studio no form appears. Application.Run has presumably already been called by the main application. I am almost completely new to forms.
How can I start the form with with my plugin (the plugin has a method that is called when it is started) and make it active?
Edit: I should clarify, the main application application window will not respond (even to minimize or maximize the window) when a plugin is running, so presumably whatever thread is devoted to handling windows messages is used to run the plugin and is, temporarily, not handling any windows messages. Thus my form needs its own thread handling windows messages.
You will need to initialize your code from whatever method the plugin architecture defined as the entry point (where the application will call your plugin).
To show a form, you can call the Show method on it.
// In a method that the plugin framework calls
myPluginForm.Show();
The application that loads your plugin should have some facility to load a window. Check the API documentation. Also, do you know if there are other plugins that can create arbitrary new windows? Usually, the host application can allow the plugin to create certain predefined (by the host) types of windows (such as config, load a file, etc...).
It might also be possible to programmaticaly create a new form and then load it. See here for an example: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx and look for the "examples" section.

Create separate window from Console Application

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.

Is there a way to bring an application's GUI to the current desktop?

Background:
Started a fair amount of work before realizing that a Windows Service cannot start an app with a GUI that displays without potential problems. The proper solution of separating the GUI of the app to be started is non-trivial, so I'm trying to think of alternative solutions.
There is a GUI to manage the service that is a separate executable, but the process to be launched (actually multiple instances of it) has its own GUI that needs to be shown. It doesn't need to be made visible by the service itself, but it needs to be at least able to be made visible by another process with a visible GUI. The Windows User that is running the service and that needs to see the GUI of the launched process is the same and known at install time.
Is there some way to accomplish this or is it back to the drawing board?
Also both the service and the app to launch are both our code and modifiable.
My first thought was to suggest that you look at the WTS* functions and CreateProcessAsUser and then I followed the link you provided and saw that you have already considered this and dismissed it.
As an alternative, if I understood you correctly you have a Windows Service and GUI which is used to manage the service. So why not use the communication channel you have between the Service and the management GUI to send a message from the service to the management GUI and have the management GUI launch the other GUI apps on behalf of the service? Of course this would assume that the management GUI is always running.
You might even do this with a hidden application that is not visible and launches when the user logs-in, that way you reduce the risk of the user inadvertantly closing the application, this would be a separate app from the actual management application.

Categories

Resources