Solved

How to refresh WPF label by vb.net code?

Posted on 2009-07-14
3
1,553 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Object to array 7 28
DataGridView 2 29
MS access and calling saved Queries 4 26
Get String split 5 33
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now