API - requires delay between command

Hi,
my application communicates with MK via c# class(http://wiki.mikrotik.com/wiki/API_in_C_Sharp). If I send a little(30) of records queue tree, sometimes mikrotik some(1-10) record not add. If is delay between record(50 ms), it is better.
Mangle that do not like QT, mangle is ok.
Please, how can I solve this problem?

Thans for all response.

to make it clear - if you send in commands to create entries in queue tree and there are a lot of commands, then first ones are not executed? In other parts of RouterOS that does not cause any problem.

can be seen if send in 30 or more commands.

like that?

maybe you could show example what you are adding?

            mikrotik = new MK("10.0.0.1");
            if (!mikrotik.Login("admin", "secretPassword"))
            {
                listBox1.Items.Add("Error");
                mikrotik.Close();
                return;
            }
            else
            {
                listBox1.Items.Add("Lognedin");
            }
            
            // create parents
            for (int a = 0; a < 30; a++)
            {

                mikrotik.Send("/queue/tree/add");
                mikrotik.Send("=name=d_" + a.ToString());
                mikrotik.Send("=parent=LAN");
                mikrotik.Send("=queue=default");
                mikrotik.Send("=priority=8");
                mikrotik.Send("=limit-at=100");
                mikrotik.Send("=max-limit=101");
                mikrotik.Send(".tag=sss", true);

                mikrotik.Send("/queue/tree/add");
                mikrotik.Send("=name=u_" + a.ToString());
                mikrotik.Send("=parent=ether2");
                mikrotik.Send("=queue=default");
                mikrotik.Send("=priority=8");
                mikrotik.Send("=limit-at=100");
                mikrotik.Send("=max-limit=101");
                mikrotik.Send(".tag=sss", true);
            }

            Thread.Sleep(500);

            // create childs
            for (int a = 0; a < 30; a++)
            {
                for (int i = 0; i < 10; i++)
                {

                    mikrotik.Send("/queue/tree/add");
                    mikrotik.Send("=name=d_" + a.ToString() + "_" + i.ToString());
                    mikrotik.Send("=parent=d_" + a.ToString());
                    mikrotik.Send("=queue=default");
                    mikrotik.Send("=priority=8");
                    mikrotik.Send("=limit-at=100");
                    mikrotik.Send("=max-limit=100");
                    mikrotik.Send("=packet-mark=d_" + a.ToString() + "_" + i.ToString());
                    mikrotik.Send(".tag=sss", true);

                    mikrotik.Send("/queue/tree/add");
                    mikrotik.Send("=name=u_" + a.ToString() + "_" + i.ToString());
                    mikrotik.Send("=parent=u_" + a.ToString());
                    mikrotik.Send("=queue=default");
                    mikrotik.Send("=priority=8");
                    mikrotik.Send("=limit-at=100");
                    mikrotik.Send("=max-limit=101");
                    mikrotik.Send("=packet-mark=u_" + a.ToString() + "_" + i.ToString());
                    mikrotik.Send(".tag=sss", true);
                }

            }

If I remove “Thread.Sleep(500);” a lot of child will not create.

you only send. what about reading? there’s response from server after each command =)

p.s. about your example: API can execute several commands simultaneously and asynchronously, so if you send a command that will create a parent and then a command that will create child - you can receive fail if parent is still not created. so first you need to get response that parent is created - and now you can use it in following commands

Chupaka is right, you have to ensure that parent is created before sending command to create child.