Q:

usage of Dispatcher class

My code is as,
Ping ping = new Ping();
ping.PingCompleted += ping_PingCompleted;
ping.SendAsync(strTerminalName, 60, Encoding.ASCII.GetBytes("sfk"));

 private void ping_PingCompleted(object sender, PingCompletedEventArgs e)
 {
    Terminal.ChangeTerminalStatus(this.imgCurrent, TerminalStatus.UserOFF);
 }

Terminal has static method ChangeTerminalStatus which i am calling in that ping_PingCompleted.
ERROR i got :-
The calling thread cannot access this object because a different thread owns it WPF.

Since i tried to change UI Property of a window in that statis method.
I searched and got solution to use  Dispatcher.BeginInvoke method.
When i tried to use this in a class which i has ping , Dispatcher.BeginInvoke
it throws error says
Error   2   An object reference is required for the non-static field, method, or property 'System.Windows.Threading.Dispatcher.BeginInvoke(System.Delegate, params object[])'   D:\Net Projects\mercurial\icafemanager\ICMBusiness\Terminal.cs  124 17  ICM

Help me out in this.

A:

BeginInvoke is not a static method of the Dispatcher class. You need a dispatcher instance to call it. In your tutorial, the class your were calling it from probably had a member that was named dispatcher, so it could be called as
this.Dispatcher.BeginInvoke(...);

If you need the current Dispatcher, there is a static property CurrentDispatcher to get it:
Dispatcher.CurrentDispatcher.BeginInvoke(...);

If your class already has a dispatcher object associated though, it's probably faster to use that.

