none
Two processes - handle errors - concept_ RRS feed

  • Question

  • Hello,

    I have a user interface that maps two processes.
    For each process, a product is manufactured that goes through various process steps 1 to 5.

    If an error occurs in process 2, it must be ensured that process 1 is empty.

    For example, if process 2 in State4 is an error and process 1 in State1, wait until process 1 completes successfully.
    When an error message should appears.

    UserInterface
    |
    |
    |----------------------------------------------------------------	
    |	
    |Process 01 lane 1
    |......o current Product
    |..............State1........State2.....State3....State4.........State5
    |
    |
    |Process 02  lane 2
    |...... o current Product
    |..............State1........State2.....State3....State4.........State5
    |
    |
    |

    Can be

    |Process 01 lane 1
    |...………………………………….o current Product
    |..............State1........State2.....State3....State4.........State5
    |
    |
    |Process 02  lane 2
    |...………………………………………………………………………………………………………………….. o current Product --> ERROR
    |..............State1........State2.....State3....State4.........State5

    Greetings Markus
    Monday, March 11, 2019 5:34 PM

All replies

  • For example, if process 2 in State4 is an error and process 1 in State1, wait until process 1 completes successfully.

    What if process1 completes unsuccessfully?


    Monday, March 11, 2019 10:31 PM
  • Hi Markus Freitag,

    Thank you for posting here.

    Could you provide a code sample for me to test? Only the description I could not reproduce the situation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 12, 2019 3:11 AM
    Moderator
  • It seems to me that you should be using Windows Workflow for this to control the processes, steps and states within a process along with event notification. 

    https://andreioros.com/blog/windows-workflow-foundation-2017/

    https://docs.microsoft.com/en-us/dotnet/framework/windows-workflow-foundation/getting-started-tutorial

    WF is not that hard to pickup, but you should get a good book on WF. It  is no more than specifying code in a step/activity, telling WF what to do on logical success or failure condition within a step/activity and  a the path to take and what to do. It's like building a flowchart, the graphics of it. And you can execute .NET code against any .NET technology within a given step/activity.

    It is fascinating stuff that Windows Workflow right there at your finger tips. :) 

    Tuesday, March 12, 2019 5:55 AM
  • Hi Wendy,
    I do not have any code yet. The problem is.
    I have a user interface for messages for the operator.
    If a track/process is going to fault, I can not stop right away, otherwise the other track/process will also go to fault.
    It must be ensured that if a fault exists, the other process has been successfully completed. I have to lock the processes together.
    The individual processes are finished. Changing it to WPF now, I do not get the necessary time from my boss. I have no experience there.
    I think if the process1 has error I have to check an event WainOne until process2 is done. Or it comes timeout,
    process2 will never finish, for whatever reason.
    I'm not sure if that's good, what the reason for the question is and was.

    ManualResetEvent EvTrack02.IsBusy = new ManualResetEvent(false);
    If track02 is empty, each error can show immediately.
    I need to check Track01 for busy or never use it.
    Error
    Track02.EvIsBusy.WaitOne(5000)
    ErrorMessage
    Stop
    test
    bool busyTrack02 = Track02.EvIsBusy.WaitOne(0)
    if (busyTrack02==true)
        Track02.EvIsBusy.WaitOne(5000)
    else
       ErrorMessage("ERROR XY")

    Summary
    If not set, the message is displayed immediately.
    How can I check the status and maybe wait 5000 ms?   Maybe somebody know a good way, a good solution. Thanks in advance.

    Greetings Markus
    Tuesday, March 12, 2019 5:14 PM
  • The key here is that there needs to be some overseer process that is monitoring these two.  The two processes should not be monitoring each other; they need to focus on their work, and only their work.

    So, each process will need a "Completed" event.  Put the two event handles in an array, then use WaitAll with a timeout.  If you hit the timeout, you'll know one (or both) process did not complete.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, March 12, 2019 9:38 PM

  • Hello Tim,
    >Put the two event handles in an array, then use WaitAll with a timeout.
    Thank you for your tip. Looks good.
    Do you know what the third parameter does? true or false?
    WaitHandle.WaitAll(new WaitHandle[] { MREvNotBusyTrack01, MREvNotBusyTrack02 }, 3000, false);
    Can you perhaps optimize the example?
    Thanks in advance.
    Greetings Markus
    class Program
    {
    	public class ManagerErrorhandling
    	{
    		public ManualResetEvent MREvNotBusyTrack01 = new ManualResetEvent(true);
    		public ManualResetEvent MREvNotBusyTrack02 = new ManualResetEvent(true);
    
    		public bool GetReleaseForErrorMessage()
    		{
    			// true normal way
    			// false timeout
    			bool ret = true;
    			ret = WaitHandle.WaitAll(new WaitHandle[] { MREvNotBusyTrack01, MREvNotBusyTrack02 }, 3000, false);
    			return ret;
    		}
    	}
    
    
    	public static CommonData Common;
    
    	public class CommonData
    	{
    		public static ManagerErrorhandling ErrorManager;
    
    		public Track01 Lane1;
    		public Track02 Lane2;
    
    		public CommonData()
    		{
    			if (ErrorManager == null)
    				ErrorManager = new ManagerErrorhandling();
    
    			Lane1 = new Track01();
    			Lane2 = new Track02();
    
    
    			Task track01 = Task.Run(() =>
    			{
    				while (true)
    				{
    					Lane1.Step1();
    					Lane1.Step2();
    					Lane1.Step3();
    
    					Thread.Sleep(2000);
    				}
    			});
    
    			Task track02 = Task.Run(() =>
    			{
    				while (true)
    				{
    					Lane2.Step1();
    					Lane2.Step2();
    					Lane2.Step3();
    
    					Thread.Sleep(1000);
    				}
    			});
    		}
    	}
    
    	public class BaseTrack
    	{
    		public BaseTrack()
    		{
    			if (CommonData.ErrorManager == null)
    				CommonData.ErrorManager = new ManagerErrorhandling();
    		}
    
    		public virtual void Step1()
    		{
    		}
    
    		public virtual void Step2()
    		{
    		}
    
    		public virtual void Step3()
    		{
    		}
    	}
    
    	public class Track01 : BaseTrack
    	{
    		public Track01()
    		{
    		}
    
    		public override void Step1()
    		{
    			CommonData.ErrorManager.MREvNotBusyTrack01.Reset();
    		}
    
    		public override void Step2()
    		{
    			CommonData.ErrorManager.MREvNotBusyTrack01.Set();
    			Console.WriteLine("Error in Step 2, track 01");
    
    			bool ret = CommonData.ErrorManager.GetReleaseForErrorMessage();
    			if (ret == true)
    				Console.WriteLine("Error - normal");
    			else
    				Console.WriteLine("Error - Timeout");
    
    
    		}
    
    		public override void Step3()
    		{
    
    			CommonData.ErrorManager.MREvNotBusyTrack01.Set();
    		}
    	}
    
    	public class Track02 : BaseTrack
    	{
    		public Track02()
    		{
    		}
    
    		public override void Step1()
    		{
    			CommonData.ErrorManager.MREvNotBusyTrack02.Reset();
    		}
    
    		public override void Step2()
    		{
    		}
    
    		public override void Step3()
    		{
    			Thread.Sleep(3500);
    
    			CommonData.ErrorManager.MREvNotBusyTrack02.Set();
    		}
    	}
    
    	static void Main(string[] args)
    	{
    		if (Common == null)
    			Common = new CommonData();
    
    		Console.ReadKey();
    	}
    }
    Monday, April 22, 2019 10:15 AM