acemuzzy

Hi,

Thanks in advance for any help. Sorry if it's a silly question - though I have done a quick search of the forums and found nothing.

I'm aware that, because of the way XNA uses the graphics device, standard windows buttons etc. can't be used in the main game window. So I wrote a quick form to show some diagnostics / settings outside of the main window. All OK.

I now want that form to have a 'save as' button, to save the current file I've been editing in the underlying XNA code. However when I launch a SaveFileDialog from the form I get a "System.Threading.ThreadStateException".

Is that because XNA doesn't like modal forms Why does it handle my form OK but not this standard dialgo

I'm guessing I could write my own Save As dialog, write it non-modally, and then that would work ok But is there anyway to get round this using the standard windows dialog Or do I have to reinvent the wheel

Pseudo code:

Game.Update()
{
MyForm form1 = new MyForm();
myForm.Show();

// use a delegate to wait for the non-modal MyForm to close
}

class MyForm
{
MyForm() // Constructor

SaveAsButton_Click (,)
{
SaveFileDialog sfd = new SaveFileDialog();
// set members

result = sfd.ShowDialog(); // -> Error
}
}


Thanks a lot!



Re: XNA Game Studio Express XNA + Standard Dialogs

Jim Perry

Have you tried:

myForm.ShowDialog();

instead of just Show()






Re: XNA Game Studio Express XNA + Standard Dialogs

acemuzzy

Hi,

Thanks.

Yes, I tried myForm.ShowDialog() with exactly the same result.

In fact, myForm.ShowDialog() doesn't run the form modally (which I would have expected). Instead, XNA keeps on going in the background - which makes me wonder if having a truly modal dialog is giving it issues.

Thanks for your help though!

M





Re: XNA Game Studio Express XNA + Standard Dialogs

gvigelet

[STAThread]

static void Main(string[] args)

{

using (Game1 game = new Game1())

{

game.Run();

}

}

Putting the [STAThread] in front of the Main function of your game will allow you to call the com component savefiledialog, in the manner that you wish.

By doing this you initialize the thread for com interops, allowing you to make com calls within your program.

Thanks,

George Vigelette






Re: XNA Game Studio Express XNA + Standard Dialogs

acemuzzy

Excellent - that seems to work! Doubt I'd have found that one out very easily, time for me to learn about threading!

Cheers,

Murray