I have it:
ThreadPool.QueueUserWorkItem(new WaitCallback(FireAttackProc), fireResult);
and FireAttackProc:
private void FireAttackProc(Object stateInfo)
{
lock (_procLock)
{
String status = "(Away vs. Home)";
FireResult fireResult = (FireResult)stateInfo;
GameModel.HomeCellStatusSet(fireResult.FireGridLocation, Cell.cellState.Lock);
this.Invoke(new Action(delegate() { RefreshHomeGrid(); }));
status = status + "(Attack Coordinate: (" + GameModel.alphaCoords(fireResult.FireGridLocation.Column) +
"," + fireResult.FireGridLocation.Row + "))(Result: ";
if (audio)
{
String Letters;
Stream stream;
SoundPlayer player;
Letters = GameModel.alphaCoords(fireResult.FireGridLocation.Column);
stream = Properties.Resources.ResourceManager.GetStream("_" + Letters);
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
Letters = fireResult.FireGridLocation.Row.ToString();
stream = Properties.Resources.ResourceManager.GetStream("__" + Letters);
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
stream.Dispose();
player.Dispose();
}
if (audio)
{
SoundPlayer fire = new SoundPlayer(Properties.Resources.fire);
fire.PlaySync();
fire.Dispose();
}
switch (fireResult.Hit)
{
case true:
this.Invoke(new Action(delegate()
{
GameModel.HomeCellStatusSet(fireResult.FireGridLocation, Cell.cellState.Hit);
status = status + "(Hit)";
}));
if (audio)
{
SoundPlayer hit = new SoundPlayer(Properties.Resources.firehit);
hit.PlaySync();
hit.Dispose();
}
break;
case false:
this.Invoke(new Action(delegate()
{
GameModel.HomeCellStatusSet(fireResult.FireGridLocation, Cell.cellState.Miss);
status = status + "(Miss)";
}));
GameModel.PlayerNextTurn = NietzscheBattleshipsGameModel.GamePlayers.Home;
if (audio)
{
SoundPlayer miss = new SoundPlayer(Properties.Resources.firemiss);
miss.PlaySync();
miss.Dispose();
}
break;
}
this.Invoke(new Action(delegate() { RefreshHomeGrid(); }));
GameToolStripStatusLabel.Text = status + ")";
if (fireResult.ShipDestroyed)
{
status = status + "(Destroyed: " + GameModel.getShipDescription(fireResult.DestroyedShipType) + ")";
if (audio)
{
Stream stream;
SoundPlayer player;
stream = Properties.Resources.ResourceManager.GetStream("_home");
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
player.Dispose();
stream.Dispose();
string ShipID = fireResult.DestroyedShipType.ToString();
stream = Properties.Resources.ResourceManager.GetStream("_" + ShipID);
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
player.Dispose();
stream.Dispose();
stream = Properties.Resources.ResourceManager.GetStream("_destroyed");
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
player.Dispose();
stream.Dispose();
}
}
if (fireResult.Win)
{
if (audio)
{
Stream stream;
SoundPlayer player;
stream = Properties.Resources.ResourceManager.GetStream("_home");
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
player.Dispose();
stream = Properties.Resources.ResourceManager.GetStream("_loses");
player = new System.Media.SoundPlayer(stream);
player.PlaySync();
player.Dispose();
}
GameModel.gameContracts = new GameContracts();
}
if (fireResult.Hit)
{
if (!fireResult.Win)
{
status = status + "(Turn: Away)";
LockGUIControls();
}
}
if (GameModel.PlayerNextTurn == NietzscheBattleshipsGameModel.GamePlayers.Home)
{
this.Invoke(new Action(delegate()
{
if (!fireResult.Win)
{
status = status + "(Turn: Home)";
AwayTableLayoutPanel.Enabled = true;
}
}));
}
if (fireResult.Win)
{
this.Invoke(new Action(delegate()
{
status = status + "(Game: Home Loses)";
CancelToolStripMenuItem.Enabled = false;
NewToolStripMenuItem.Enabled = true;
LockGUIControls();
}));
}
GameToolStripStatusLabel.Text = status + ")";
}
}
The problem is this:
In Vista / win7, sound clips in FireAttackProc are played.
But under XP, the logic contained in FireAttackProc runs, but none of the sound clips play.
Is there a quick solution for this so that the sound is played under XP?
I am asking for a quick solution because I am happy that I can fully execute Vista / Win7, but it would be great if there was a quick solution, so it would also be with XP compilation.
Thank.
iTEgg source
share