【发布时间】:2011-05-03 20:03:00
【问题描述】:
(关于我之前的一个问题:Playing a Video (MSDN Tutorial))
我有以下问题:当我试图读取 XNA VideoPlayer 对象的状态时,我得到一个CrossThreadMessagingException。意思是,我正在尝试从不同的线程中读取。这似乎是不允许的(我不知道线程在 C# 内部是如何工作的 :-)
关于如何解决这个问题的任何想法? (有没有办法告诉 VideoPlayer 对象写入缓冲区或其他东西?)
代码:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (player.State == MediaState.Stopped) //Causes the exception
{
player.IsLooped = true;
player.Play(video); //Causes the "mysterious" crash
}
// ...
}
错误信息:
player.State = 'player.State' threw anexception of type'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException'
【问题讨论】:
-
这是一个调试器异常;这不是真正的问题。
标签: c# multithreading exception xna