0

SOには同様の質問がたくさんあります。しかし、私はかなり奇妙な状況にあります.Dispatcher.CurrentDispatcher.Invoke内で実行されている間にこの例外が発生します. 修正方法がわかりません。

これが私の StackTrace です (ディスパッチャーがそこで呼び出されていることがわかります):

   at System.Windows.Input.InputManager..ctor()
   at

System.Windows.Input.InputManager.GetCurrentInputManagerImpl() で System.Windows.Input.KeyboardNavigation..ctor() で System.Windows.FrameworkElement.FrameworkServices..ctor() で System.Windows.FrameworkElement.EnsureFrameworkServices() で System. Windows.FrameworkElement..ctor() の System.Windows.Controls.Control..ctor() の System.Windows.Controls.UserControl..ctor() の MCC.PresentationUtilities.ClosingAwareViewModelUserControl..ctor() の MCC.TherapyDeviceManager。 D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.PatientDetailUI\Views\PatientDetailView.xaml.cs:11 行目の MCC.TherapyDeviceManager.MultipleViewHost.Managers.TabItemFactory.PatientTabItemFactory.CreateEditableView にある PatientDetailUI.Views.PatientDetailView..ctor() (PatientDetailViewModel vm) D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.MultipleViewHost\Managers\TabItemFactory\PatientTabItemFactory.cs: D:\WTS\ の MCC.TherapyDeviceManager.MultipleViewHost.Managers.TabItemFactory.PatientTabItemFactory.Create(SelectedPatientChangedEventArgs 患者、IClosableController& コントローラー) の 41 行目D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager. MultipleViewHost\Managers\PatientEventsManager.cs: D:\WTS\WTS3\WTS\MCC の MCC.TherapyDeviceManager.MultipleViewHost.Managers.PatientEventsManager.AddPatientView(SelectedPatientChangedEventArgspatientInfo) の 94 行目。TherapyDeviceManager.MultipleViewHost\Managers\PatientEventsManager.cs: D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.MultipleViewHost\Managers\PatientEventsManager.cs の MCC.TherapyDeviceManager.MultipleViewHost.Managers.PatientEventsManager.DataImportFinishedHandler(DataImportFinishedEventArgs dataImportFinishedEventArgs) の 75 行目: Microsoft.Practices.Composite.Events.EventSubscription の 41 行目1.InvokeAction(Action1 アクション、TPayload 引数) D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.Definitions\Prism\EventSubscription.cs:122 行目 Microsoft.Practices.Composite.Events.EventSubscription 1.<>c__DisplayClass2.<GetExecutionStrategy>b__0(Object[] arguments) in D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.Definitions\Prism\EventSubscription.cs:line 108 at Microsoft.Practices.Composite.Events.EventBase.InternalPublish(Object[] arguments) in D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.Definitions\Prism\EventBase.cs:line 69 at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent1.Publish(TPayload ペイロード) in D: \WTS\WTS3\WTS\MCC.TherapyDeviceManager.Definitions\Prism\CompositePresentationEvent.cs: MCC.TherapyDeviceManager.DeviceManager.DataRecordManager .<>c_DisplayClass5.b の 168 行目_4() in D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.DeviceManager\DataRecordManager.cs:MS.Internal の System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) の 247 行目。 Threading.ExceptionFilterHelper.TryCatchWhen (オブジェクト ソース、デリゲート メソッド、オブジェクト引数、Int32 numArgs、デリゲート catchHandler) で System.Windows.Threading.DispatcherOperation.InvokeImpl() で System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(オブジェクト状態) で System. System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup (TryCode コード、CleanupCode backoutCode、オブジェクト userData) で System.Threading.ExecutionContext で Threading.ExecutionContext.runTryCode (オブジェクト userData)。System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態、Boolean ignoreSyncCtx) で System.Threading.ExecutionContext.Run(ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態) で RunInternal(ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態) System.Windows.Threading.DispatcherOperation.Invoke() で System.Windows.Threading.Dispatcher.ProcessQueue() で System.Windows.Threading.Dispatcher.WndProcHook (IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean& を処理) System.Windows.System.Windows.Threading.Dispatcher. MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam) の InvokeImpl(DispatcherPriority 優先度、TimeSpan タイムアウト、デリゲート メソッド、オブジェクト引数、Int32 numArgs) MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame フレーム) で System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame フレーム) で System.Windows.Threading.DispatcherOperation.Wait(TimeSpan タイムアウト) で System.System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority 優先度、TimeSpan タイムアウト、Delegate メソッド、Object args、Int32 numArgs)、System.Windows.Threading.Dispatcher.Invoke(Delegate メソッド、Object[] args)、MCC.TherapyDeviceManager.DeviceManager.DataRecordManager でD:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.DeviceManager\DataRecordManager.cs:D の MCC.TherapyDeviceManager.DeviceManager.DataRecordManager.Process(DetectedDeviceInfo detectedDeviceInfo) の 247 行目の .DataImportedIntoDb(Patient patient, DetectedDevice detectedDevice, DataRecord dataRecord) :\WTS\WTS3\WTS\MCC.TherapyDeviceManager.DeviceManager\DataRecordManager.cs:D:\WTS\WTS3\WTS\MCC の MCC.TherapyDeviceManager.DeviceManager.DeviceToDatabaseSaverManager.CreateOrUpdateDeviceEntity(IDeviceDataInfo deviceDataInfo) の 66 行目。TherapyDeviceManager.DeviceManager\DeviceToDatabaseSaverManager.cs: D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.DeviceManager\DeviceToDatabaseSaverManager.cs の MCC.TherapyDeviceManager.DeviceManager.DeviceToDatabaseSaverManager.FoundDevice(IDeviceDataInfo deviceDataInfo) の 106 行目: MCC.TherapyDeviceManager の 88 行目D:\WTS\WTS3\WTS\MCC.TherapyDeviceManager.DeviceManager\DeviceToDatabaseSaverManager.cs:MCC.Devices.DeviceDetection.ConnectionManagers.ConnectionManagerAggregator.OnDeviceDetected(DetectedDeviceInfoEventArgs e) の 70 行目の .DeviceManager.DeviceToDatabaseSaverManager.DeviceDetectedHandler(Object sender, DetectedDeviceInfoEventArgs e) ) D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\ConnectionManagerAggregator.cs:MCC.Devices.DeviceDetection の 22 行目。D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\ConnectionManagerAggregator.cs:MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase の 58 行目の ConnectionManagers.ConnectionManagerAggregator.DeviceDetectedHandler(Object sender, DetectedDeviceInfoEventArgs e)2.OnDeviceDetected(DetectedDeviceInfoEventArgs e) in D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:line 33 at MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase2.D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase の 258 行目の AddDevice(TConnection 接続、DeviceData デバイス) 2.FoundDevice(TConnection connection, DeviceData newlyDetectedDevice) in D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:line 229 at MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase2.DetectDeviceOnAquiredConnection(TConnection 接続) D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:185 行目 MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase 2.Poll(TConnection connection) in D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:line 166 at MCC.Devices.DeviceDetection.ConnectionManagers.Managers.SdConnectionManager.Poll(FileConnection connection) in D:\WTS\WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\Managers\SdConnectionManager.cs:line 51 at MCC.Devices.DeviceDetection.ConnectionManagers.SpecificConnectionManagerBase2.PollingCycle(Object tokenObject, TConnectionMetadata detectedConnectionMetadata) in D:\WTS \WTS3\WTS\MCC.Devices.DetectService\ConnectionManagers\SpecificConnectionManagerBase.cs:142行目

4

1 に答える 1

2

メインスレッド以外のスレッドを使用している場合、を使用Dispatcher.CurrentDispatcherすると、コードは現在のスレッドで実行されたままになり、メインスレッドには移動しません。また、他のスレッドで UI コンポーネント (コントロールなど) を作成することはできません。

あなたがすべきことは、DispatcherUI オブジェクトのプロパティを使用することです。アクセスできない場合は、 を使用できますApplication.Current

于 2011-09-05T06:33:30.643 に答える