1
我做出從其他引用的項目的UI組件幾個電話通過接口清爽不工作
UI組分:
Public Class PleaseWaitWindow
Implements PleaseWaitInterface
Sub New(initStateText As String)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
tbStateDescription.Text = initStateText
Me.Activate()
End Sub
Public Property currentStepText As String Implements PleaseWaitInterface.currentStepText
Get
Return tbStateDescription.Text
End Get
Set(value As String)
tbStateDescription.Text = value
tbStateDescription.InvalidateVisual()
End Set
End Property
Public Sub Display() Implements PleaseWaitInterface.Display
Me.Show()
Me.Activate()
End Sub
Public Sub Dispose() Implements PleaseWaitInterface.Dispose
Me.Close()
End Sub
Public Property maxSteps As Integer Implements PleaseWaitInterface.maxSteps
Get
Return pbCurrentProgress.Maximum
End Get
Set(value As Integer)
pbCurrentProgress.Maximum = value
End Set
End Property
Public Sub PerformStep() Implements PleaseWaitInterface.PerformStep
pbCurrentProgress.Value += 1
pbCurrentProgress.InvalidateVisual()
End Sub
End Class
只要我做這些調用從同一項目的一切內工作
喜歡這裏:
Private Function startGeneration_normal() As Boolean
//Do some stuff
pw.PerformStep()
pw.currentStepText = ("Loading data, no stepping is available.")
tar.startworking(pw)
//Do some stuff
End Function
但是當我通過在terfaceobject到引用的項目,並嘗試使用這樣的:
Public Function startworking(pw As PleaseWaitInterface) As Boolean
tempExportFileName = "Export" & DateTime.Now.ToString("yyyy-MM-dd_HH.mm")
//Do some stuff
pw.currentStepText = ("Current Task: formating XML")
//Do some more stuff
End Function
對象中的變化(在調試器檢查)的值,但視覺效果不刷新,直到從startworking功能start_generate函數返回。當它從引用項目中的函數返回時,將根據當前狀態刷新值。
爲什麼在程序執行引用項目中的內容時UI不刷新?
你似乎在UI線程同步運行的代碼,所以它被封鎖,也不會更新任何東西。您應該使用像BackgroundWorker這樣的異步機制。 – Clemens
謝謝你的工作 – lsteinme