InvalidOperationException при проверке CaptureSource.State - PullRequest
0 голосов
/ 23 марта 2012

Я создал класс, производный от System.Windows.Media.AudioSink для обеспечения возможности записи. Чтобы проверить состояние моей бетонной раковины, я делаю следующее:

public class MyViewModel
{
    private readonly MyAudioSink _myAudioSink; // this field is ensured in the ctor
    public bool IsRecording
    {
        get
        {
            if (this._myAudioSink == null)
            {
                return false; // I know that `false` is wrong ...
            }
            return this._myAudioSink.CaptureSource.State == CaptureState.Started;
        }
    }
}

Иногда, когда я запрашиваю против свойства IsRecording, я получаю следующее исключение:

{System.InvalidOperationException: Capture source is not stopped
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh)
   at System.Windows.Media.CaptureSource..ctor()
   at MS.Internal.CoreTypes.GetCoreWrapper(UInt32 typeId)
   at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference)
   at MS.Internal.XcpImports.ConvertDO(IntPtr doPointer, Int32 typeIndex, Boolean releaseObjectReference)
   at MS.Internal.XcpImports.ConvertType(CValue outVal, Int32 typeIndex, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject)
   at MS.Internal.XcpImports.AudioSink_GetSource(AudioSink Sink)
   at System.Windows.Media.AudioSink.get_CaptureSource()
   at MyViewModel.get_IsRecording()

Иногда, когда я делаю this._myAudioSink.Stop(), я получаю следующее (похожее) исключение:

{System.InvalidOperationException: Capture source is not stopped
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh)
   at System.Windows.Media.CaptureSource..ctor()
   at MS.Internal.CoreTypes.GetCoreWrapper(UInt32 typeId)
   at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference)
   at MS.Internal.XcpImports.ConvertDO(IntPtr doPointer, Int32 typeIndex, Boolean releaseObjectReference)
   at MS.Internal.XcpImports.ConvertType(CValue outVal, Int32 typeIndex, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject)
   at MS.Internal.XcpImports.AudioSink_GetSource(AudioSink Sink)
   at System.Windows.Media.AudioSink.get_CaptureSource()

Так ... в чем причина? Как я могу предотвратить это исключение (кроме введения собственного поля и установки его в переопределениях OnCaptureStarted и OnCaptureStopped)?

Единственная тема по этой проблеме, которую я нашел в сети, это здесь ...

1 Ответ

0 голосов
/ 20 августа 2012

Я закончил с переопределением определенных команд (OnCaptureStopped, OnCaptureStarted, ..), чтобы инкапсулировать состояние в моей модели .

Очевидно, что это помогает, и у меня больше никогда не было проблем.

PS: Я где-то читал, что инкапсуляция captureSource должна быть достаточной - я не могу предоставить ссылку ... она где-то там, сэр!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...