Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to refresh WPF label by vb.net code?

Posted on 2009-07-14
3
Medium Priority
?
1,852 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

722 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