Sorry for not addressing your issue immediately; from your question and code sample it's not clear what's going on; please see my comment to the question.
However, there is something you should re-thing first. This line looks just funny:
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,new ParameterizedThreadStart(action), state);
It looks scary. It gives makes me suspect that you have no idea what
Dispatcher
ispatcher.BeginInvoke or
Dispatcher.Invoke
; otherwise why would you use this strange
ParameterizedThreadStart
delegate type? All trouble may become apparent if you look at what is "action" in this line of code.
What's funny, formally you can use this delegate type, but it has nothing to do with the purpose of invocation. The invocation with the use of
Dispatcher
is a way to delegate a call from some arbitrary thread to a UI thread (UI thread and nothing else).
For this reason, you need to use the dispatcher instance of the Control using the property
System.Windows.Threading.DispatcherObject.Dispatcher
(as
Control is DispatcherObject
). It could be your status bar, but it is not really important what exactly control is this. It should be some instance of the Control created and added to you UI by a UI thread.
The delegate type used in
Dispatcher.BeginInvoke
or
Dispatcher.Invoke
can be
any delegate type with by-value parameters of reference or value types (out or ref parameters also could be used but it makes no sense). The call takes all data needed to a call — handler entry point, "this" reference of the instance of the object where the method is declared (if, any, null for static method), all the values of the call parameters — and queue this data to some queue which is accessible to the UI thread. The call itself is not done be the UI thread using this data from the UI and never by the thread calling
Invoke
eginInvoke.
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
—SA