Solved

How to refresh WPF label by vb.net code?

Posted on 2009-07-14
3
1,632 Views
Last Modified: 2014-07-02
i need to update a WPF label with lets say "Start Process" then loop some work and at the end update label with "Process complete." the problem is that the first "start Process" text never appear only the last text appear, WPF has no DOEvents code like VB FORMS.

i saw some C# code to do this with lambada delegates but i despretlly need VB.NET code that does this task.

Appretiate any help, Regards.
0
Comment
Question by:amir9383
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24857792
I used the C# code from this site and converted it to VB.NET using and online code

http://dedjo.blogspot.com/2007/08/how-to-doevents-in-wpf.html

You can also still use the Application.DoEvents if you add the reference to the DLL. Check here
http://nmarian.blogspot.com/2007/09/doevents-in-wpf.html

Read this article as well
http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx

 
 
   1. Private Sub DoEvents()
   2.     Dim f As New DispatcherFrame()
   3.     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, DirectCast(Function(ByVal arg As Object) Do
   4.         Dim fr As DispatcherFrame = TryCast(arg, DispatcherFrame)
   5.         fr.[Continue] = [True]
   6.     End Function, SendOrPostCallback), f)
   7.     Dispatcher.PushFrame(frame)
   8. End Sub

Open in new window

0
 

Accepted Solution

by:
amir9383 earned 0 total points
ID: 24867084
hi, Thanks for the suggestions!

regard windows.forms.doevents() it does not achive the affect needed the application update the WPF label only after the loop processing (in my case some ftp connection check).

regard the converted code it has errors (for example the DO statement says "expression expected" error and the "arg is not declared.

I have googled up (a lot)  and find this solution in VB:

Imports System.Windows.Threading
Imports System.Threading

Public Sub DoEvents()

        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, New ThreadStart(AddressOf doNothing))

End Sub

Public Sub doNothing()

End Sub

i have added this to my custom control and call DoEvents() beofre my looping and the control has rendered properly, after my looping was over i have change the label again and the feedback to the user properly showned. (Strangely i had also to change the button event (the button that started the process) to "Release" mode. that refine the visual feedback even more.

hope that will help to others.

Regards,
0
 

Expert Comment

by:petel2k
ID: 40172785
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(() => System.Threading.Thread.Sleep(1)));

Seems to solve the problem
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question