Hi!
I need to write a piece of code that has to be executed in turn, e.g. first A, then B, then C then D. The methods have to be called async, but the flow of events is sync. I solved this by adding:
- a delegate called HandleDataDelegate
- an event called HandleData
The class that does the work has four methods A, B, C, D all with different work but same signature void (string, string) when they are ready they raise an event handleData passing the result as a string
HandleData("this is my result")
In the "main" method I have methods OnADone, OnBDone, OnCDone, OnDDone that kick off a call to B, C or D. In the onDDone Everything is finished and the program ends. And to Control which of the eventhandlers that will get the result I do Before I call the method B, I add a handler to it's handleData event so that OnBDone will be used. And in OnBDone, I remove the handler and set the handler to OnCDone Before I call C and so on.
This feels like a very clumpsy way to solve the problem, but it works and I haven't found any better way to handle this, since the methods A-D have an async call in them. The platform I work on doesn't support await, async and Tasks... :(
Can anyone please help me to "streamline" the flow described, it feels like there is work to be done, for example can't I use the func<> to dynamically Control which method to be called? It would sure save some lines of code...
/S
I need to write a piece of code that has to be executed in turn, e.g. first A, then B, then C then D. The methods have to be called async, but the flow of events is sync. I solved this by adding:
- a delegate called HandleDataDelegate
- an event called HandleData
The class that does the work has four methods A, B, C, D all with different work but same signature void (string, string) when they are ready they raise an event handleData passing the result as a string
HandleData("this is my result")
In the "main" method I have methods OnADone, OnBDone, OnCDone, OnDDone that kick off a call to B, C or D. In the onDDone Everything is finished and the program ends. And to Control which of the eventhandlers that will get the result I do Before I call the method B, I add a handler to it's handleData event so that OnBDone will be used. And in OnBDone, I remove the handler and set the handler to OnCDone Before I call C and so on.
This feels like a very clumpsy way to solve the problem, but it works and I haven't found any better way to handle this, since the methods A-D have an async call in them. The platform I work on doesn't support await, async and Tasks... :(
Can anyone please help me to "streamline" the flow described, it feels like there is work to be done, for example can't I use the func<> to dynamically Control which method to be called? It would sure save some lines of code...
/S