Ever had one of those problems where you are coding outside your normal zone, but you know the answer is simple, and can’t get the syntax right on the day?
Friday was one of those days, here is the outline of my problem, I am refractoring one of my customer tests, its a windows form, and instead of having all the code within the form itself, I am moving it to a MVP layout, not a problem overall you may think, currently it has a bunch of controls, a couple of results text box’s and a process button.
So I created the view, and started creating the presenter, now the current form uses a background worker, so i wanted to move that to the tasks layer, where the actual work would be called, the presenter being responsible for pushing messages back to the view, and receiving the data and passing it on in the correct format to the task layer.
It was all going well, that tests pass until i got to the task layer, I create a background worker, an I want to hookup the progress and complete the events, now i don’t want the task interface to rely on the background worker, I may change it to a simple threading model so my ITask interface must have event, but this time I need to pass some data with the event and thats where i got suck, stupid i know but these things happen, so Sunday afternoon I decided to run up a quick spike to solve the interface event problem and see what the code will looklike. here is my result.
first i wrote a simple task object that would implement an interface, I extracted the interface using ReSharper (one of those little used functions, but when you need it, its a real time saver)
I know its the wrong way around, but next I wrote some tests to play with the task to see if the message was passed up to my mock presenter as I wanted.