Ticket T586271
Visible to All Users

Multi threading- Does scheduler control supports multi threading ?

created 7 years ago

I am working with  scheduler control.
Scenario- I have added a ResourcesCheckedListBoxControl for filtering the resources . For faster loading i have used Multi threading concept
When i do it normal way it loads the ResourcesCheckedListBoxControl   but when i go with threading it does not work.  .  See the following code

Visual Basic
Private Sub frmScheduler_Load(sender As Object, e As EventArgs) Handles MyBase.Load bw = New BackgroundWorker() AddHandler bw.DoWork, AddressOf bw_DoWork 'AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted bw.WorkerReportsProgress = True bw.WorkerSupportsCancellation = True If bw.IsBusy = False Then MarqueeProgressBarControl1.Visible = True bw.RunWorkerAsync() End If End sub Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Dim worker As BackgroundWorker = CType(sender, BackgroundWorker) If bw.CancellationPending = True Then e.Cancel = True Exit Sub Else Try Parallel.Invoke(Sub() 'SchedulerControl1.DayView.TimeIndicatorDisplayOptions.ShowOverAppointment = True Me.SpSALScheduler_siudTableAdapter1.Fill(Me.ResourceDataSet.spSALScheduler_siud) End Sub, Sub() Me.SpSALScheduler_siudTableAdapter.Fill(Me.SALDataSet.spSALScheduler_siud) End Sub) Catch ex As Exception End Try End If End Sub Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) MarqueeProgressBarControl1.Visible = False If Me.InvokeRequired Then Me.Invoke(New MethodInvoker(AddressOf UpdateUI)) End If End Sub

In the above code  I have used backgrounder to show progress bar  and Parallel.Invoke for parallel filling dataset. The code work fine . but resources does not load into the ResourcesCheckedListBoxControl  .  The resources should show on the ResourcesCheckedListBoxControl .

I have tried another concept of threading please see the below code

Visual Basic
Dim task1 As Task = Task.Factory.StartNew(Function() Me.SpSALScheduler_siudTableAdapter.Fill(Me.SALDataSet.spSALScheduler_siud)) Dim task2 As Task = Task.Factory.StartNew(Function() Me.SpSALScheduler_siudTableAdapter1.Fill(Me.ResourceDataSet.spSALScheduler_siud)) 'Dim task3 As Task = Task.Factory.StartNew(Function() doStuff("Task3")) Task.WaitAll(task1, task2)

this one also fails to load ResourcesCheckedListBoxControl

Answers approved by DevExpress Support

created 7 years ago

Hello Ian,
I reproduced your scenario in a sample project. In this project, I used the ResourcesCheckedListBoxControl and DateNavigator controls bound to a current SchedulerControl instance.
In my sample project, I used BindingLists as the "appointment" and "resources" data sources.
Initially, when the ResourcesCheckedListBoxControl.SchedulerControl and DateNavigator.SchedulerControl properties were set to the current SchedulerControl instance, I got the "cross-thread" exception on generating the mentioned data sources.
I believe that in your scenario, SchedulerControl is bound to corresponding BindingSource instances.

The matter is that BindingList (as well as BindingSource) raises notifications after adding (initial loading) new items.
The "cross-thread" exception was raised on an attempt to refresh the mentioned UI controls (ResourcesCheckedListBoxControl, DateNavigator and SchedulerControl) after changing data sources within another thread.

In my sample project, I resolved this issue by re-setting the Storage.Resources.DataSource and Storage.Appointments.DataSource properties' values on the "Scheduler" form's initial loading and assigning corresponding data sources to SchedulerControl in the BackgroundWorker.RunWorkerCompleted  event handler.
Please check the attached sample. I hope you will find this sample helpful.

If this sample does not help you resolve the issue, please modify it or provide me with your project which I can use to reproduce the problematic behavior.
I look forward to your response.

    Show previous comments (8)
    DevExpress Support Team 7 years ago

      Hello Ian,
      I have attached two versions of my previous project to demonstrate how you can filter resources that do not contain appointments using the following approaches:
      - filtering at the data source level
      - filtering at the SchedulerControl level by changing the Resource.Visible property value.
      I hope you will find these samples helpful.

      IM IM
      Ian MacDonald 2 7 years ago

        Thanks Oleg Its working correctly. Now i want to change the resource dynamically So i have added one resource group control, which contains different resources radio buttons. According to radio button checked i have to shoe the resource belong s to the appointment .  Its working correctly for Division and Room resource But when i tried for location and client its does show the appointment. I have tried to figure out but i dont. I am attaching sample for code for reference.

        DevExpress Support Team 7 years ago

          Hi Ian,
          I have investigated the new version of you project and found the cause of this issue.
          The SchedulerControl keeps binding to the "resources" data table while reloading data using a background worker. When you generate new records for the "ResourceTable" table, the SchedulerControl tries to regenerate its resources.
          Since the "ResourceTable" records are re-created in a background thread, there is an issue with re-generating the SchedulerControl resources.
          In addition, it is incorrect to change the "resources" and "appointments" mappings before re-setting the "appointment" and "resources" data source.

          I have attached the modified version of your project to demonstrate how to resolve these issues.
          In this sample, I also moved your code for creating a BackgroundWorker instance and subscribing to the BackgroundWorker events outside the StartBackgroundWorker method.
          Please check this sample and let me know how it operates on your side.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.