1

我会解释,但代码可以比我更好地解释它。

我正在尝试获取 2 个变量的值
我在它的类上创建一个新对象并使用它的成员,我从数据包中设置它们的值。
每当我尝试访问它们时,我都会发现它们为零,这对我来说没有意义。
这是与问题相关的代码的重要部分

public class PacketHandler
    {
.
. dots means unrelated long code
.
public PacketHandler()
        {
        }
        public ushort actualX { get; set; }
        public ushort actualY { get; set; }
.
.
.
case 10010:
                            {
                                if (BitConverter.ToUInt16(data, 8) == 1002)
                                {
                                    actualX = BitConverter.ToUInt16(data, 24);
                                    actualY = BitConverter.ToUInt16(data, 26);
                                }
                                break;

这是我试图获得价值的另一类

public class ClientBase
{
    GameUser role2;
    PacketHandler ph = new PacketHandler(); <<<<<<<<
    public ClientBase(GameUser role)
    {
        role2 = role;
        Thread T = new Thread(HuntThread) { Name = "Hunt Thread" };
        T.Start(this);
        Console.WriteLine("with name : " +T.Name +  " with execution context : "+T.ExecutionContext +" with state : "+ T.IsAlive + " with id : " + T.ManagedThreadId);
       T.Join();
    }
    Monster GetNextkill()
    {
        Monster CurrentTarget = null;
        foreach (KeyValuePair<uint, Monster> Pair in Dictionary.Clone(Dictionary.Monsters))
        {

                CurrentTarget = Pair.Value;
        }
        return CurrentTarget;
    }
    public void HuntThread(object Sender)
    {
        try
        {
            ClientBase Client = Sender as ClientBase;
            while (true)
            {
                Monster Target = GetNextkill();
                if (Target != null)
                {
                    Thread.Sleep(1000);
                    ProxyParadise.Network.Packets.PacketStructure ps = new ProxyParadise.Network.Packets.PacketStructure();

                    ps.__Packet10010(Target.X, Target.Y, role2, "normal", "server", ph.actualX, ph.actualY); <<<<< i get zeros at the ph.actualX/Y
                    Thread.Sleep(1000);
                    ps.__Packet10010(Target.X, Target.Y, role2, "sdasdsa", "client", role2.X, role2.Y);
                    Thread.Sleep(1000);
                    ps.__Packet1022NONEXP(Target.UID, Target.X , Target.Y, role2);
                    Dictionary.Monsters.SafeRemove(Target.UID);

如果我听起来很愚蠢,请原谅我,为了更清楚,我想要一种在新线程中通过类传输数据的正确方法。
请尝试将其应用于此示例以便更好地理解。
有一个美好的一天

4

0 回答 0