static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // get application GUID as defined in AssemblyInfo.cs // unique id for global mutex - Global prefix means it is global to the machine string mutexId = string.Format("Global\\{{{0}}}", appGuid); using (var mutex = new Mutex(false, mutexId)) { try { if (!mutex.WaitOne(0, false)) { //signal existing app via named pipes JSONobject j = new JSONobject(); j.action = "dial"; j.data = new Data(); j.data.telnr = args[0].Remove(0, 4).Trim('/'); Pipe p = new Pipe("OTMPipe"); p.send(JsonConvert.SerializeObject(j)); Environment.Exit(0); } else { // handle protocol with this instance Program.f = new frm_main(); Application.Run(f); } } finally { mutex.ReleaseMutex(); } } }
private void frm_main_Load(object sender, EventArgs e) { Boolean success = frm_main.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 0x0000, 0x42);//Set hotkey as 'b'Boolean success = Form1.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 0x0000, 0x42);//Set hotkey as 'b' this.lbl_1.Focus(); if(this.settings["serverPort"] == null || this.settings["serverHost"] == null || this.settings["clientPort"] == null) { this.changeState("full"); frm_settings f = new frm_settings(); f.Show(); MessageBox.Show("Er ontbreken instellingen!"); } else { Con = new UDPlink(this.settings["serverHost"], Convert.ToInt32(this.settings["serverPort"]), Convert.ToInt32(this.settings["clientPort"])); Con.subscribeMatchMaker(); userH = new userH(this, Con); P = new Pipe("OTMPipe"); P.form = this; P.createPipeServer(); this.KeyPreview = true; this.KeyDown += new KeyEventHandler(userH.keyDown); } }