Individual thread management

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 769
Благодарностей
1 179
Баллы
113
This is a must feature guys. There are many questions and requests around from users about this.
I personally have such need in so many projects.
What I mean is. We need thread ID when thread is started it is possible to get this id.
Later in template or in other template we can access this thread id and manage it. Like Stop it - in case something is wrong with thread. Like our year thread freeze bug what still comes out time to time. If would be possible to get access to this threads variables what is currently working then this would be awesome x10.
@VladZen please ask developers if this is possible in some extent. ? And if this is something we could see implemented. ?
Thanks
 
  • Спасибо
Реакции: myndeswx

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 189
Благодарностей
5 831
Баллы
113
Thread ID can be obtained with this code:
C#:
return instance.ZP_ID;
or
C#:
return Thread.CurrentThread.ManagedThreadId.ToString();
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 769
Благодарностей
1 179
Баллы
113
  • Спасибо
Реакции: myndeswx

myndeswx

Client
Регистрация
15.05.2017
Сообщения
399
Благодарностей
88
Баллы
28

myndeswx

Client
Регистрация
15.05.2017
Сообщения
399
Благодарностей
88
Баллы
28
Posting this here, this 'pinger' can be used to send alive signals from individual thread to know if it's alive or not.
The problem is though, that it doesn't work on ZD, something really strange is happening.
This code would send 'ping' requests every 10 seconds while the template is running, and stop when the template stops, and it works perfectly on ZP, BUT on the droid when template is finished it keeps sending the requests!

Even after we delete the template from the ZD - the requests still being sent. Maybe the threads are working somewhat differently on the droid?
Really need help with it, because this is the only workaround to thread control I can think of.

Thank you.

C#:
namespace ZennoLab.OwnCode
{
    /// <summary>
    /// A simple class of the common code
    /// </summary>
    public class CommonCode
    {
        /// <summary>
        /// Lock this object to mark part of code for single thread execution
        /// </summary>
        public static object SyncObject = new object();

        // Insert your code here
       
        #region Pinger
       
        public static async System.Threading.Tasks.Task Pinger(IZennoPosterProjectModel project)
        {
            await System.Threading.Tasks.Task.Run(() =>
            {
                project.SendToLog("Pinger Start", ZennoLab.InterfacesLibrary.Enums.Log.LogType.Info, true, ZennoLab.InterfacesLibrary.Enums.Log.LogColor.Green);
               
                project.Variables["pinger"].Value = true.ToString();

                while (true)
                {
                    try { if (Convert.ToBoolean(project.Variables["pinger"].Value) != true) { project.SendToLog("Pinger Stop", ZennoLab.InterfacesLibrary.Enums.Log.LogType.Info, true, ZennoLab.InterfacesLibrary.Enums.Log.LogColor.Red); break; } } catch { }
                   
                    ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, project.Variables["pinger_url"].Value, content: project.Variables["pinger_post"].Value, contentPostingType: project.Variables["pinger_content_type"].Value, Timeout: 30000);
                   
                    File.WriteAllText(project.Directory + "\\async_log.txt", DateTime.Now.ToString("HH:mm:ss"));
                   
                    Thread.Sleep(Convert.ToInt32(project.Variables["pinger_request_delay"].Value) * 1000);
                }
            });
        }
       
        #endregion
    }
}
 
Последнее редактирование:

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 189
Благодарностей
5 831
Баллы
113
  • Спасибо
Реакции: myndeswx

myndeswx

Client
Регистрация
15.05.2017
Сообщения
399
Благодарностей
88
Баллы
28
Ok, I see what thread management is needed. I'll discuss this functionality with developers.
Meanwhile, I suggest you read this topic:
Thank you for the link, it's a good read with really useful information.
Could you also please watch the video I posted above? Maybe developers would have to say something about that because it's extremely strange IMO, and the strangest part is that the same code works in ZP , but not in ZD, so hopefully it's fixable? )
Thank you!
:bt:
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 189
Благодарностей
5 831
Баллы
113
Thank you for the link, it's a good read with really useful information.
Could you also please watch the video I posted above? Maybe developers would have to say something about that because it's extremely strange IMO, and the strangest part is that the same code works in ZP , but not in ZD, so hopefully it's fixable? )
Thank you!
:bt:
ZennoDroid is another program. C# APi from zennoposter does not work in it.
 

myndeswx

Client
Регистрация
15.05.2017
Сообщения
399
Благодарностей
88
Баллы
28
ZennoDroid is another program. C# APi from zennoposter does not work in it.
Wouldn't say so strictly about it, because the same C# code partly works, it does send the HTTP post requests as it's supposed to.
The only thing that is not working- it doesn't detect when the thread ends I think.

Anyways, we do really need a way to get a status of an individual thread for ZD as well as ZP.
Thanks for help as always!
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 189
Благодарностей
5 831
Баллы
113
How can I stop/interrupt this exact thread from code ? From other template by this ID ? How can I do ANY management with this thread by ID ?
These .Net methods can be used to manage threads in zennoposter.
 
  • Спасибо
Реакции: myndeswx

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)