Dispatcher Interface for Mocking

As I’ve wrote the integration tests for the pick module which also included the multi-threaded class, I’ve faced problem that the dispatcher in the multi-threaded class fails to mock. Since the multi-threaded class is used to refresh the data grid view within time interval, therefore fails to mock had caused all the integration tests fail to receive the data grid binding source to perform testing.

In order to solve the issue, I’ve decided to use the solution which is implement an interface for the dispatcher for mocking.

I’ve created the interface which called IDispatcher which include the BeginInvoke method. Then, instead of calling dispatcher, I’ve changed it to fire IDispatcher and its method as well. Lastly, in the integration tests, I call the mock for IDispatcher and setup its callback as (Action a) => a() to invoke the method in the multi-threaded class.

Multithreading with EventWaitHandle

For the week, I’ve found the bug caused the pick module thread fails to refresh the sales order data grid view. This is because when the data grid collection had been initialize with new data at outside of the thread, it will no longer able to update the data grid collection and reflect in UI.

Therefore, I’ve implement EventWaitHandle to solve the issue. When user had clicked on the filter sales order check box, it send signal to the thread in order to refresh the sales order data grid view immediately. While the thread will always loop the function at 5 seconds interval by using WaitOne(TimeSpan.FromSeconds(5));

Not only that, I’ve also set the EventResetMode to AutoReset which will always set the event state to false after received signal.

Multithreading on Pick module

For this week, I’ve continue to develop on the new task which is the pick module. After the UI creation is completed, I’ve inserted some dummy data to test the UI. However, in order to make sure the user always get the latest sales order data from the database for pick module, multithreading is applied to the module.

Multithreading is used in the pick module which aim to refresh the sales order data and update the UI data grid view at the background. Not only that, it also require retrieve the latest row version in order to avoid concurrency error.

However, I’ve faced problem which update data grid binding source in the thread does not reflect in the UI data grid view even thought I’ve define a new collection for the binding source. After I’ve search for solution on the Internet, I’ve learned that I should call dispatcher for UI updating work and for the binding source, I’m only allowed to perform .Clear(), .Add(), AddRange(), and Remove() instead of defining new collection.