Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WPF MVVM MultiThread Interattività

4 views
Skip to first unread message

Flavio Miano

unread,
Feb 11, 2010, 3:59:35 PM2/11/10
to
Desideravo creare una applicazione che esegua qualche operazione
con la possibilit� di annullare.

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

Corrado Cavalli [MVP]

unread,
Feb 11, 2010, 4:07:11 PM2/11/10
to
Flavio Miano has brought this to us :

> Desideravo creare una applicazione che esegua qualche operazione
> con la possibilitᅵ di annullare.
> 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/


0 new messages