0

I have a button for which I receive a click command via bluetooth, and this happens on a different thread:

 //Auto click record button
                    if (action_type_received_final == 0)
                    {
                        ButtonAutomationPeer peer2 = new ButtonAutomationPeer(Btn_Record);
                        IInvokeProvider invokeProv2 = peer2.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                        //invokeProv2.Invoke();
                        Dispatcher.Invoke(new ThreadStart(() => invokeProv2.Invoke()));

                        action_type_received_final = 0;
                    }

The code runs fine, but nothing happens on the UI. I understand that I have to come back to the UI thread somehow, but I just don't know how. I would appreciate any help.

Ivan
  • 1,081
  • 2
  • 17
  • 43
  • Did you search for similar questions? http://stackoverflow.com/questions/2626390/c-sharp-communication-between-threads – stark Aug 27 '15 at 00:30
  • Yes, almost anything I tried didn't work – Ivan Aug 27 '15 at 00:50
  • At this point in your code, do you have a reference to the window, form or any control? – Philippe Paré Aug 27 '15 at 02:07
  • See also https://stackoverflow.com/questions/2382663/ensuring-that-things-run-on-the-ui-thread-in-wpf, and the many other questions on Stack Overflow involving WPF's `Dispatcher` object. – Peter Duniho Aug 27 '15 at 02:43

0 Answers0