A
A
Andrey2018-08-02 12:24:41
C++ / C#
Andrey, 2018-08-02 12:24:41

How to output data from the DispatcherTimer to the UI without waiting for it to complete?

Good day everyone! Please tell me how to overcome this problem:
The WPF application, on a timer, makes a request to the database, fills in the fields with the received data (all fields are inside the Border) and then the content of the border is printed. The problem is that the data is transferred to the UI later than printing takes place. THOSE. in the timer, the print is triggered, a blank sheet is printed, then the timer completes its work and the data appears in the UI.
Are there any solutions to "stop the timer", pass the data to the UI, print it and keep it running?
Where to dig?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melz, 2018-08-02
@andrey71

UI is updated in a separate thread via dispatcher. In your case, he still did not have time to do his job.
those or do sleep-delay or something like this:

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, (Action)delegate()
  {
     Todo: print
  });

You can still increase the priority of the dispatcher, but this is not an idea.

L
LiptonOlolo, 2018-08-03
@LiptonOlolo

Use MVVM and all problems will disappear by themselves.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question