Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sorry for the question title.
i have problem when using a OPC API.

this API declare a delegate ReadCompleteEventHandler Internally,
somehow in subscription.Read(), it pass ItemValueResult[] into the Mydelegate.

ItemValueResult[] is what i need. I can use it inside ReadCompleteCallback.
however, I am making it into a window form, another class, then trouble comes.


class tester
    {
        public  void Work()
        {
            ReadCompleteEventHandler Mydelegate = new ReadCompleteEventHandler(ReadCompleteCallback);

            subscription.Read(subscription.Items, 123, Mydelegate, out req);
           
        }

static  void ReadCompleteCallback(object nn,ItemValueResult[] mm)
        {
            MessageBox.Show(mm); //mm can only use in my Tester Class
        
        }
    }


What I have tried:

in tester Class:
public  ItemValueResult[] resultinTesterClass;
       static  void ReadCompleteCallback(object nn,ItemValueResult[]mm)
       {
           MessageBox.Show(mm);
         resultinTesterClass = mm;

       }


where in the form1:

public ItemValueResult[] resultinFormClass
        private void ButtonRead_Click(object sender, EventArgs e)
        {
            obj.Work();
            resultinFormClass=obj.resultinTesterClass;
        }


I think it is too indirect and somethime resultinFormClass return null.
Any conventional way to solve.
thank you!
Posted

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