0

ファイルに書き込むスレッド セーフなログ クラスを作成する割り当てがあります。10 フレームごとに、選択した情報を別のスクリプトからロギング クラスにプッシュすることになっています。私はそれをどのように行うのか疑問に思っていました。これまでの私のコードは次のとおりです。

public class Threading
{

    public bool Execute = true;
    public Vector3 player;
    public Vector3 WriteTime;
    System.Collections.Generic.Queue<float> values;
    // Use this for initialization
    void Start ()
    {

    }

    // Update is called once per frame
    void Update () 
    {

    }
    public void execute()
    {
        while (Execute)
        {
            System.Threading.Thread.Sleep(500);
            values.Enqueue(player.x);
            UnityEngine.Debug.Log("value");
        }

        System.IO.StreamWriter write = new System.IO.StreamWriter("values.txt"); // writes to file every 5 seconds

        while (values.Count > 0)
        {
            WriteTime = write.WriteLine(values.Dequeue().ToString());
        }
        write.Close();
    }

    public void Lock() // applied Lock threading
    {

            while(true)
            {
                lock (this)
                {
                   // dont have anything here yet. Trying to figure out locks
                }
            }

    }

ありがとうございました。

4

0 に答える 0