From Microsoft's doccumentation on Dispatcher (emphasis mine):
In WPF, a
DispatcherObject can only be accessed by the
Dispatcher it is associated with. For example, a background thread cannot update the contents of a
Button that is associated with the
Dispatcher on the UI thread. In order for the background thread to access the
Content property of the Button, the background thread must delegate the work to the
Dispatcher associated with the UI thread. This is accomplished by using either
Invoke is synchronous and
BeginInvoke is asynchronous. The operation is added to the queue of the
Dispatcher at the specified
So basically what you're doing is call an asynchronous method, and then forcing it to run on the UI thread, which accomplishes nothing.
//Other function calls here omitted, I'm asuming that you need to access some part of the UI, if that's not the case, all you have to do is remove the
Dispatcher.Invoke from your method.
If my assumptions are right, then you must figure out a way of splitting your function, so that the part that isn't UI related run in a Background thread and only what needs to run on the UI Thread actually do.
My suggestion is to use a
Background Worker. Here's how it'd look:
uiTIN.Click += (o, e) =>
... and then ...
private int job()
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
// Part of other function calls here omitted that don't need to run on the UI thread
// Part of other function calls here omitted that must run on the UI thread