Solved

How to refresh WPF label by vb.net code?

Posted on 2009-07-14
3
1,730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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