MDI Child Waiting On Another Child
-
I'm working on a hobby war simulation game in Visual C++ .NET and am having a problem with multithreading. I don't know much about it, and am wondering if there may even be a better solution than multithreading for this problem: The game is running in an MDI parent with multiple forms. A user wants to move units from one city to another; The Main Menu child tells the Map child that it needs the user to select a target city. I want the Main Menu to pause its code processing at that point until the user selects a city, which then is passed back to the Main Menu so it may continue processing. The problem I am running into is this: The player selects an invalid city to move to -- I want to generate another MDI child that acts as a popup to inform them they can't move there and what their options are. When I do this (as shown in the code below) the new Popup child flashes on the screen for just a moment then disappears. I am guessing that this is because the Military_MoveThread is ending, so it closes anything initialized in the thread, but I am not really sure why it does this. I want the thread to end but the new MDI child popup to remain on the screen. I've tried running the popup as a new thread but it does exactly the same thing. Here is basically what I have:
//In the Main Menu -- Once player selects move: void InitiateMove() { ThreadStart *myThreadDelegate = new ThreadStart(this, Military_MoveThread); trd = new Thread(myThreadDelegate); trd->IsBackground = true; trd->Start(); } void Military_MoveThread() { //Opens the map form for selection theClient->EnableMap(); //Tells the map form that we are looking for a target theMap->iTargetMode = 1; //Sit and wait until the map decides we have a target while( theMap->iTargetMode == 1 ) { Thread::Sleep( 100 ); } //If they cancled the selection, return to normal mode if( theClient->iTargetCity == -1 ) { theClient->EnableAllForms(); theMap->EnableAllCities(); return; } //If they selected a city that isn't valid, pop up MDI child message box if( theClient->PlayerOwnsCity( theClient->iTargetCity ) == false && theClient->clientCityButtons[ theClient->iTargetCity ]->iOwner != -1 ) { Popup( String::Concat( S"Master ", theClient->Name, S", that city does not belong to us!" ) ); theMap->EnableAllCities(); theClient->iTargetCity = -1; return; } //***Code continues below for movement*** } void Popup( S