wpf - Correct way to call Dispatcher.Invoke -


Why does the following code work on Win7 PC, but can I get a MissingMethodException and Timer.Elapsed event a Can also be interpreted as never said.

  private sub _timer2_Elapsed (ByVal as this object, ByVal e System.EventArgs) as handle _timer2.Elapsed _timer2.Enabled = false Dispatcher.Invoke (sub () HandleSingleKeyPress (-1 ) End sub) End sub  

some after that I found the following code works much better: -

  public representative sub InvokedSubDelegate ( ) Private sub _timer2_Elapsed (ByVal as this object, ByVal e System.EventArgs) as handle _timer2.Elapsed _timer2.Enabled = false Dispatcher.Invoke (new InvokedSubDelegate (sub () HandleSingleKeyPress (-1) End sub)) End Sub  

Definitely Why do not already have access ACH can only sometimes works but hopefully resolved by someone else with similar problems.

Jerry

It is not true that you are close to identifying the right problem Are there. Definitely more than one in that snippet.

A mistake method exception is a DLL problem. In other words, you are running your code with the old version of assembly, which has no such system till now which you are trying to call. Avoid DLL Hell by paying a lot of attention when you deploy the assemblies. And [assembly version] has been promoted religiously in VB.NET IDE with project + properties, application tab, assembly information button. Explain that 2 pieces seem for this problem, then you are less likely to be running with that older version of the assembly.

This does not end it is rather bad when you use the system. Tires Timer classes are taken in a dirty section in an extremely Acuktapuarn lapse of judgment, Microsoft decided to swallow all exceptions which passed the event handler. Which tells why the timer stops working, it will not do just what you said to do when the exception closes the code. Satisfying the system. Timer class, it does not swallow exceptions or always do try in the regeneration of handler / hold, although it is very difficult to figure out when you'll catch environment. Ex () is intelligent.

But most of all, you are using the completely wrong timer. When you make it synchronous using the Dispatcher, then there is no point in using asynchronous. Just use a DispatcherTimer instead, you get exactly the same result, zero to zero and overhead. And it is necessary to ask this question.


Comments