Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on a software where software issues commands for hardware panel and once a command is issued, its response received after few seconds . there are different functions for different hardware commands like
C#
public void FunctionA()
{
     StartCommandA();
}
and other functions on the same pattern that will be used to run other commands.
C#
FunctionB();
FunctionC();
Once we receive the response of command A , I invoke the other function from the response but this approach is not good as per design pattern practices.

All i want to do is to make a list of functions and invoke all these functions one after other, But next function will be called once i get response of first functions.

What I have tried:

I tried this by using Multicast delegate but I'm unable to find out how we can call get the list of functions once i add all functions to that delegates. This is what i'm trying do since.
C#
FunList funList_ConfigAndSerialTests = new FunList(StartSerialTest);

            funList_ConfigAndSerialTests += StartSerialTest;

            funList_ConfigAndSerialTests += StartMsrTest;

            funList_ConfigAndSerialTests += StartContactLessTest;

            //funList_ConfigAndSerialTests.Invoke();

            Delegate[] del = funList_ConfigAndSerialTests.GetInvocationList();

            foreach (Delegate item in funList_ConfigAndSerialTests.GetInvocationList())
            {
                while (true)
                {
                    if (IsResponseReceived == true)
                    {
                        // Call function here 
                    }
                }
            }
Posted
Updated 23-Jan-18 20:51pm
Comments
Richard Deeming 23-Jan-18 10:01am    
How are the responses received? You'd probably do better with an async / await approach.
Ammar Shaukat 23-Jan-18 11:11am    
function call is async and response received in a separate method named like "OnResponse"
Richard Deeming 23-Jan-18 11:15am    
Is OnResponse an event handler? If not, how is it invoked?
Ammar Shaukat 23-Jan-18 11:21am    
yup its an Event handler

have a look at the Task class Task Class (System.Threading.Tasks)[^]
and to the ContinueWith methods.

This is what you want: call methods each in it's own Task (thread) - wait for method to execute while not blocking the rest of your app. After executing continue with next method call (in it's own Task). Also see the new syntactic Support for this pattern (aync/await Keywords)
 
Share this answer
 
Comments
Ammar Shaukat 23-Jan-18 11:13am    
We area already working with Tasks and function calls are async calls. Response function call is received in a separate function whose name is like "OnResponse"
Make a list of
C#
Action
Delegates and add Status Code for each function . let's say 0 mean function has invoked and 1 mean function is not invoked yet. then use LINQ Query to check which function has called and which one is remaining.
Change the status of function invocation from
C#
OnReponse
Method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900