Thursday, March 3, 2011

the function equivalent to "doevent" in vb 6

The function equivalent to "doevent" in vb 6


In vb6 programming"doevent" is function that useful when you want to update your text on your form while you are using loop. unfortunately that this function is not exist in vb.net. but we can use this code below to have similar result.


    Private Delegate Sub EmptyDelegate()

    Public Sub DoEvents()
                    System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, New EmptyDelegate(AddressOf mfunction))
    End Sub

    Private Sub mfunction()
           'just leave it empty...
    End Sub

sample to use :
you want to update your text during the loop

dim i as integer
for i = 1 to 1000
     label1.text = "this is label in loop ..." & i
     DoEvents()
next

No comments:

Post a Comment