qui il mio Viewmodel test
Imports System.ComponentModel
Imports System.Windows.Threading
Imports System.Threading
Public Class TestViewmodel
Implements INotifyPropertyChanged
Private _Progress As Integer
Public Property Progress() As Integer
Get
Return _Progress
End Get
Set(ByVal value As Integer)
_Progress = (value Mod 10000) + 1
RaiseEvent PropertyChanged(Me, New
PropertyChangedEventArgs("Progress"))
' System.Windows.Forms.Application.DoEvents()
End Set
End Property
Private InProgress As Boolean
Public Sub Start()
InProgress = True
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
New ThreadStart(AddressOf Job))
End Sub
Public Sub [Stop]()
InProgress = False
End Sub
Private Sub Job()
Do
Progress += 1
Loop While InProgress
End Sub
Public Event PropertyChanged(ByVal sender As Object, ByVal e As
System.ComponentModel.PropertyChangedEventArgs) Implements
System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
progress � bindato ad una textbox ed a una progressbar
nella form ho anche due pulsanti che eseguono start e stop del viewmodel
domanda :
quando aggiorno la property progress nel loop
si blocca tutto
ho provato anche con
dim th as new thread(addressof(job))
th.start()
ma niente
Soluzione ?
Grazie Flavio
Francamente non capisco cosa c'entri il codice che ha scritto con
multithreading e background operation in generale. Se vuoi
semplificarti la vita considera l'uso della classe BackgroundWorker.
--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://blogs.ugidotnet.org/corrado/