private void btn_TestTater(object sender, RoutedEventArgs e) { IP_Tato tater = new IP_Tato(); tater.Explode(); Task showDialogBox = Task.Run(() => { // This will update the GUI with the results of the tater EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.ManualReset); Application app = Application.Current; app.Dispatcher.Invoke((Action) delegate { Game_Popup game_Popup = new Game_Popup(tater); // Try to update GUI from this thread. // The ShowDialog is the perfect function for this. // It blocks until the window is closed which is all I needed it to do. game_Popup.Show(); // If I can Wait outside of this dispatcher, then it should be best game_Popup.Closing += (object send, System.ComponentModel.CancelEventArgs eargs) => { ewh.Set(); }; }); // Event Listener ewh.WaitOne(); // Timeout check // Return whether the potato was requested to be passed. return(true); }); Console.WriteLine("The Popup has completed its task."); }
private static object ProcessPotato(object obj) { // Some of these commands should be placed in the potato object // Because they then can be protected // Create IP_Tato IP_Tato tater = obj as IP_Tato; // Add the current host to the holderHistory // This is done on the client side for pessimism's sake // tater.AddCurrentHostToHolderHistory(); // Instead set the previous client to self tater.LastClient = tater.TargetClient; // Pseudocode // Check Flags of tater // Do stuff according to the flags on tater // Flags are stored as bools and should be assigned by // * names rather than position. // Flag Precedence is a thing a potato should explode before other things happen. // Print last player that tater was passed from // "$player passed a potato to you" // Check if number of passes is done. // Greater than used to catch too many passes. if (tater.Passes == 0) { tater.Explode(); } // This will update the GUI with the results of the tater Application app = Application.Current; if (app == null) { Main(); app = Current; } app.Dispatcher.Invoke((Action) delegate { // Try to update GUI from this thread. Game_Popup game_Popup = new Game_Popup(tater); // The ShowDialog is the perfect function for this. // It blocks until the window is closed which is all I needed it to do. game_Popup.ShowDialog(); }); // Increment current passes // This is done at the end in case of an involuntary host disconnect tater.Passes--; return(tater as object); }
private static object ProcessPotato(object obj) { // Some of these commands should be placed in the potato object // Because they then can be protected // Create IP_Tato IP_Tato tater = obj as IP_Tato; // Increment current passes tater.Passes--; // Add the current host to the holderHistory // This is done on the client side for pessimism's sake // tater.AddCurrentHostToHolderHistory(); // Instead set the previous client to self tater.LastClient = tater.TargetClient; // Pseudocode // Check Flags of tater // Do stuff according to the flags on tater // Flags are stored as bools and should be assigned by // * names rather than position. // Flag Precedence is a thing a potato should explode before other things happen. // Print last player that tater was passed from // "$player passed a potato to you" // Check if number of passes is done. // Greater than used to catch too many passes. if (tater.Passes == 0) { tater.Explode(); } return(tater as object); }
private object ProcessRequest(object receivedObject) { object objectResponse = "ERR:ProcessFailure"; if (receivedObject is IP_Tato) { // Process the IP_Tato IP_Tato tater = receivedObject as IP_Tato; tater.Passes--; // Check if tater has exploded if (tater.Passes == 0) { tater.Explode(); objectResponse = tater; // OnRaiseClientDisconnectedEvent(ClientInfo); } // Set up a EventWaitHandle to block code execution until the popup is closing. EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.ManualReset); bool taterIsPassed = false; // Update the GUI with the results of the tater Application app = Application.Current; app.Dispatcher.Invoke((Action) delegate { // Create a new popup Game_Popup game_Popup = new Game_Popup(tater); // Show the popup game_Popup.Show(); // Set up an event handler to capture the results of the popup game_Popup.Closing += (object send, System.ComponentModel.CancelEventArgs eargs) => { taterIsPassed = game_Popup.Passing; ewh.Set(); }; }); if (tater.Exploded) { ewh.Set(); for (int x = 0; x < 10; x++) { app.Dispatcher.Invoke((Action) delegate { // Create a new popup Game_Popup game_Popup = new Game_Popup(tater); // Show the popup game_Popup.Show(); }); } // OnRaiseClientDisconnectedEvent(ClientInfo); } // Block until the popup closing event fires. ewh.WaitOne(); if (taterIsPassed || tater.Exploded) { // Set the previous client to the current client. tater.LastClient = tater.TargetClient; objectResponse = tater; } else { OnRaiseClientDisconnectedEvent(ClientInfo); objectResponse = "RESPONSE:Disconnect"; } } return(objectResponse); }