0
namespace TOC
{
delegate void message_fPtoEMS(Message msg);
delegate void message_fEMStoMax(Message msg);
delegate void message_fMaxtoEMS(Message msg);
delegate void message_fEMStoP(Message msg);
public partial class Form1 : Form
{
    public  void Controller()
    {
        Patient agentP = new Patient("agentP");  
        EMS agentEMS = new EMS("agentEMS");
        Max agentAI = new Max("agentAI");

        agentP.fPatienttoEMS = new 
        message_fPtoEMS(agentEMS.Receive_from_Patient); 
        agentEMS.fEMStoAI = new message_fEMStoMax(agentAI.Receive_from_EMS);
        agentAI.fAItoEMS = new message_fMaxtoEMS(agentEMS.Receive_from_AI);
        agentEMS.fEMStoP = new message_fEMStoP(agentP.Receive_from_EMS);
        Thread T_agentP = new Thread(agentP.Run);  
        T_agentP.Start();
        Thread T_agentEMS = new Thread(agentEMS.Run);
        T_agentEMS.Start();
        Thread T_agentAI = new Thread(agentAI.Run);
        T_agentAI.Start();
    }        
    public AI_sim()
    {
        InitializeComponent();
        Thread control = new Thread(() => Controller());
        control.Start(); 
    }
    private void AI_sim_Load(object sender, EventArgs e)
    {
    }
    }
    class Patient
    {
    public string agentname;
    public Patient(string name) { agentname = name; }
    public void Run()
    {
        assignvalue();
    }
    public void assignvalue()
    {
        int age
        age = random.Next(0, 100);
        form1.textbox1.text = convert.tostring(age);

    }   // Assign Value method end...

I tried delegate solutions posted on stack overflow but didn't work. I already spent more than a week searching about it. Can someone please tell me how to update the form from Patient class. Is there any good means to make changes or control in UI form.

Eric
  • 1
  • 1
  • For what reason are there all these threads? They don't seem to be doing anything sensible. – Clemens Nov 04 '18 at 22:36
  • I am working on agent based model so all the threads are working on their defined tasks in their own class(I haven't added other classes in the code). But I need to update UI only from that patient class shown above. – Eric Nov 04 '18 at 22:51
  • I googled "Marshal call to UI Thread wpf" on Bing and got all sorts of suggestions like https://stackoverflow.com/questions/11625208/accessing-ui-main-thread-safely-in-wpf. What have you tried, what doesn't work? – Flydog57 Nov 04 '18 at 23:37

0 Answers0