How to force UI update before blocking operation? [SOLVED]

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
rkmore
Posts: 55
Joined: Mon Dec 07, 2015 1:53 pm

How to force UI update before blocking operation? [SOLVED]

Postby rkmore » Sun Mar 20, 2016 5:37 am

I have an animated GIF that I want to set to "Visible" right before I do a fairly long blocking operation.

When I do then it does not show (If I don;t do the blocking operation it shows fine).

Is there a method to cause the UI to update immediateld? A DoEvents sort of thing?

Code: Select all

                Working.Visibility = Visibility.Visible;

                Sha2.Sha256 hasher = new Sha2.Sha256();
                byte[] array = Encoding.ASCII.GetBytes(cPassword.Password + salt);
                hasher.AddData(array, 0, (uint)array.Length);
                uint[] hash = hasher.GetHashUInt32();
                StringBuilder sb = new StringBuilder();
                foreach (uint i in hash) sb.Append(i.ToString("X04"));

                App.cCollector = App.cServiceClient.GetCollectorForUserName(cUsername.Text);

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: How to force UI update before blocking operation?

Postby JS-Support @Userware » Sun Mar 20, 2016 11:27 am

Hi,

Yes, this is possible.

All you need to do is to move your long blocking operation into a Dispatcher.BeginInvoke(...) call.

Here is an example:

Code: Select all

//Here you update the UI

Dispatcher.BeginInvoke(() => {

  // Here you do the long blocking operation. This code will be executed on the UI thread as soon as the UI thread is free.

});

// The code you put here will be executed BEFORE the long blocking operation, and also BEFORE the UI update.

// As soon as this thread is finished, the UI gets updated.


You can find more information about the Dispatcher.RunAsync method online.

Thanks.
Regards,
JS-Support

rkmore
Posts: 55
Joined: Mon Dec 07, 2015 1:53 pm

Re: How to force UI update before blocking operation?

Postby rkmore » Mon Mar 21, 2016 3:30 am

That was what I tried first. I get....

Code: Select all

Error   CS1061   'CoreDispatcher' does not contain a definition for 'RunAsync' and no extension method 'RunAsync' accepting a first argument of type 'CoreDispatcher' could be found (are you missing a using directive or an assembly reference?)   


And I can find no reference that allows it. I am under 7.2

RKM

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: How to force UI update before blocking operation?

Postby JS-Support @Userware » Mon Mar 21, 2016 9:46 am

Sorry, the method name is "BeginInvoke", not "RunAsync". I have updated the previous post. Please let me know if it works.

By the way, you can find the reference of the CoreDispatcher at the following URL:
http://help.cshtml5.com/html/806f0ccc-ebed-0142-38b7-15e84693477a.htm

Regards,
JS-Support


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 36 guests