Change notification

Topics: Errors, Setup
Nov 8, 2015 at 2:49 PM
Edited Nov 8, 2015 at 3:42 PM
I'm creating a task service monitor that puts all of the root tasks into a datagrid and displays their information. I'm using a a binding source as taskservice.rootfolder.tasks and binding that to the datasource of a the datagrid. I'm having some issues with the changes to tasks propagating to the datagridview. When an automated task is run the datagridview doesn't update the appropriate information until that row is clicked.

Am I missing a way to watch for change notifications? Has anyone else tried to implement this?

The point of this app is to show real time status for all tasks. If a task is running I would like to know immediately. Having the grid refresh every second might is too taxing resource wise. After having more than 15 tasks the whole program starts to lag the system horribly.

Here is the code that I have. In a normal situation if I were using a dataset then dgv auto updates and repaints the new information.
    Dim WithEvents _tskSrvc As TaskService = Nothing
    Dim WithEvents _bSource As BindingSource = Nothing

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        _tskSrvc = New TaskService()
        _bSource = New BindingSource

        _bSource.DataSource = _tskSrvc.RootFolder.Tasks
        _bSource.RaiseListChangedEvents = True

        taskDGV2.DataSource = _bSource

    End Sub
Nov 9, 2015 at 6:14 PM
Unfortunately, there is not an easy way to do this. The TaskCollection and RunningTaskCollection instances that can be retrieved do not have any change events that would alert the consumer to changes in the underlying tasks.

In order to achieve what you are looking for, you would need to set a timer and then manually compare the lists and task properties and then update your grid. You could also just refresh the grid at some interval and re-retrieve the task list.
Nov 9, 2015 at 8:33 PM
That is what I figured. refreshing enough where it seemed instantaneous caused a huge amount of lag in the gui. The way I went about it was to have a 5 second timer to refresh the grid and a 100ms timer to check that the grid row count matched the task count and to rebind the datasource if it was a mismatch.

Thanks for the help
Nov 11, 2015 at 5:35 PM
Edited Nov 17, 2015 at 5:28 PM
In version 2.5.4 a TaskEventWatcher class has been added that will enable this. See documentation for code examples on how to use it.
Marked as answer by dahall on 11/17/2015 at 10:29 AM