Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:42:19+00:00 2026-06-14T17:42:19+00:00

What I need to do is get foreach values from one method called private

  • 0

What I need to do is get foreach values from one method called private void ReceiveData() and send them to another method void Update() . How to do that in c#?

private void ReceiveData() 
    {

       IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse("10.0.2.217"), port);
       client = new UdpClient(remoteIP);
        while (true) 
        {
           try 
            {
                IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                data = client.Receive(ref anyIP);

                int nIndex = 0;
                foreach(SignalIndex si in xmlreader.cdpSignals)
                {
                     x= ReadSingleBigEndian(data, si.index + 0);
                     y= ReadSingleBigEndian(data, si.index + 4);
                     z= ReadSingleBigEndian(data, si.index + 8);
                     alpha= ReadSingleBigEndian(data, si.index + 12);
                     theta= ReadSingleBigEndian(data, si.index + 16);
                     phi= ReadSingleBigEndian(data, si.index + 20);

                //  xmlreader.unityGameObjects[nIndex].transform.localPosition = new Vector3(x,y,z);
                //  xmlreader.unityGameObjects[nIndex].transform.Rotate(alpha,theta,phi);   
                }

            }
            catch (Exception err) 
            {
               print(err.ToString());
            }

        }

        client.Close();
    }


    void Update() 
    {
        foreach(GameObject go in xmlreader.unityGameObjects)
        {
            go.transform.localPosition = new Vector3(x,y,z);
            go.transform.transform.Rotate(alpha,theta,phi);
        }
    }

There are 2 methods and I need to get the values in foreach from ReceiveData() and instantiate them in method Update(). All variables in foreach from ReceiveData() are public, but they all takes 0 in Update().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:42:21+00:00Added an answer on June 14, 2026 at 5:42 pm

    EDIT 2:

    Documentation for ReaderWriterLockSlim: http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx

    struct CoordData
    {
        public float X, Y, Z, Alpha, Theta, Phi;
        public int NIndex;
    }
    
    private List<CoordData> coordDataList = new List<CoordData>();
    private ReaderWriterLockSlim lockObj = new ReaderWriterLockSlim();
    
    private void ReceiveData() 
    {
    
       IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse("10.0.2.217"), port);
       client = new UdpClient(remoteIP);
        while (true) 
        {
           try 
            {
                IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                data = client.Receive(ref anyIP);
    
                int nIndex = 0;
                foreach(SignalIndex si in xmlreader.cdpSignals)
                {
                     x= ReadSingleBigEndian(data, si.index + 0);
                     y= ReadSingleBigEndian(data, si.index + 4);
                     z= ReadSingleBigEndian(data, si.index + 8);
                     alpha= ReadSingleBigEndian(data, si.index + 12);
                     theta= ReadSingleBigEndian(data, si.index + 16);
                     phi= ReadSingleBigEndian(data, si.index + 20);
    
                     lockObj.EnterWriteLock();
                     try
                     {
                         coordDataList.Add(new CoordData() { X = x, Y = y, Z = z, Alpha = alpha, Theta = theta, Phi = phi, NIndex = nIndex });
                     }
                     finally
                     {
                         lockObj.ExitWriteLock();
                     }
    
                     nIndex++; //I'm assuming you want to do this here otherwise you'll be changing the same object in the array every time  
                }
    
            }
            catch (Exception err) 
            {
               print(err.ToString());
            }
    
        }
    
        client.Close();
    }
    
    void Update()
    {
        lockObj.EnterReadLock();
        try
        {
            foreach (CoordData data in coordDataList)
            {
                xmlReader.unityGameObjects[data.NIndex].localPosition = new Vector3(data.X,data.Y,data.Z);
                xmlReader.unityGameObjects[data.NIndex].Rotate(data.Alpha,data.Theta,data.Phi);
            }
        }
        finally
        {
            lockObj.ExitReadLock();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the contents from this URL http://google.fr/ok in a NSString can
I need to transfer the values from a PHP array into a JavaScript array
I have a simple method which is called from multiple threads; @Override public Bitmap
I need to get the data from multiple sensors. I have tried creating a
I need to get summary data from many many rows. The summary fields are
We need to store a list of data we pull from another table that
I need get the id of an images which is place inside a datatemplate..
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I have linq request. I need get item.Title in select. how do this? var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.