Der bliver investeret massivt i AI. Teknologien er mere tilgængelig end nogensinde, og ambitionerne er høje. Alligevel oplever mange virksomheder, at resultaterne udebliver.
Her kommer lige en ordentlig omgang kode - men det virker ;)
Først en klasse ProcessUtils, til at klare eftersøgningen af et kørende program:
[CODE] using System; using System.Diagnostics; using System.Threading; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace MyApp { /// Summary description for ProcessUtils. public static class ProcessUtils { private static Mutex mutex = null;
/// Determine if the current process is already running public static bool ThisProcessIsAlreadyRunning() { // Only want to call this method once, at startup. Debug.Assert(mutex == null);
// createdNew needs to be false in .Net 2.0, otherwise, if another instance of // this program is running, the Mutex constructor will block, and then throw // an exception if the other instance is shut down. bool createdNew = false;
mutex = new Mutex(false, Application.ProductName, out createdNew);
/// Set focus to the previous instance of the specified program. public static void SetFocusToPreviousInstance(string windowCaption) { // Look for previous instance of this program. IntPtr hWnd = FindWindow(null, windowCaption);
// If a previous instance of this program was found... if (hWnd != null) { // Is it displaying a popup window? IntPtr hPopupWnd = GetLastActivePopup(hWnd);
// If so, set focus to the popup window. Otherwise set focus // to the program's main window. if (hPopupWnd != null && IsWindowEnabled(hPopupWnd)) { hWnd = hPopupWnd; }
SetForegroundWindow(hWnd);
// If program is minimized, restore it. if (IsIconic(hWnd)) { ShowWindow(hWnd, SW_RESTORE); } } } } } [/CODE]
Så kan du i din Main metode evt. gøre følgende (Husk at bruge dit eget form navn som input parameter i SetFocusToPreviusInstance() metoden):
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.