danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
174 stars 93 forks source link

No tag is attached to sent commands #30

Closed AsafMag closed 6 years ago

AsafMag commented 6 years ago

Hello,

A tag is not attached to sent commands, which makes them take each others' responses as their own when sent in parallel.

I'm using a version of late 2017 and haven't seen a change in the latest version.

danikf commented 6 years ago

Hi, do you have sample code? Sounds very unlikely tu me ... D

AsafMag commented 6 years ago
var a = new Thread(() =>
{
    while (true)
    {
        var command = connection.CreateCommand("/system/health/print");
        command.ExecuteSingleRow();
    }
});

var b = new Thread(() =>
{
    while (true)
    {
        var command = connection.CreateCommand("/system/health/print");
        command.ExecuteSingleRow();
    }
});

a.Start();
b.Start();

One of them throws when you start b. https://wiki.mikrotik.com/wiki/Manual:API#Tags

I tried adding this parameter myself, but it wasn't added in the correct location as expected (compared to other libraries).

danikf commented 6 years ago

Could you please explain the reason for running two synchronous commands in parallel way? Tags are (of course) supported by async methods - ExecuteAsync.

Thanks, D

AsafMag commented 6 years ago

Actually I've been using ExecuteListWithDuration which uses ExecuteAsync internally, this solves the issue, I dropped the usage of ExecuteSingleRow. This now relates to what we were talking about in issue #26 - canceling one sniffing command cancels all other active ones, even though there is a tag attached to them.

danikf commented 6 years ago

Well,

I have added some support for sending .tag embeded in command rows / parameters witch could be also solution (see connected commit). Just to add more intuitive interface. But ExecuteAsync (and ExecuteListWithDuration) is the solution I would preffer.

D