Access instance property from Thread in C#

Maddo7

Client
Регистрация
09.05.2015
Сообщения
109
Благодарностей
5
Баллы
18
Hello,
I try to access the instance property from a thread in C# but it doesn't seem to work.

C#:
Task.Run(() =>
              {
              
                 project.SendInfoToLog("yo");
                
                // Action designer, type Set
                HtmlElement he = instance.ActiveTab.GetDocumentByAddress("0").FindElementByAttribute("body", "innertext", "body", "regexp", 0);


                // Set to attribute "innertext" value "closing tab"
                he.SetAttribute("innertext", "hello");
              });
This will only print "yo" to the console but not change the html element.
If I run the code without the Task, it works.

How can I access the instance element inside a Thread?
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 218
Благодарностей
5 843
Баллы
113
This means element was not found by attribute. Not the problem accessing instance property.
Where are you using this code? What element with?
 

Maddo7

Client
Регистрация
09.05.2015
Сообщения
109
Благодарностей
5
Баллы
18
This means element was not found by attribute. Not the problem accessing instance property.
Where are you using this code? What element with?
I ran it as a test on the blank page that appears on ZP.
Other methoids like instance.ActiveTab.Close(); also don't work in the Task.

I tried the exact same code I posted without the Task.Run() and it worked so I assume the incorrect instance of instance is passed to the Task.
 
Последнее редактирование:

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 218
Благодарностей
5 843
Баллы
113
I ran it as a test on the blank page that appears on ZP.
Other methoids like instance.ActiveTab.Close(); also don't work in the Task.

I tried the exact same code I posted without the Task.Run() and it worked so I assume the incorrect instance of instance is passed to the Task.
How can you test FindElement method on blank page?
Sorry, but I don't understand what you are doing.
 

Maddo7

Client
Регистрация
09.05.2015
Сообщения
109
Благодарностей
5
Баллы
18

Вложения

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 218
Благодарностей
5 843
Баллы
113
We should ask @lokiys I think..., he is C# guru)
 

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