Access instance property from Thread in C#

  • Автор темы Автор темы Maddo7
  • Дата начала Дата начала

Maddo7

Client
Регистрация
09.05.2015
Сообщения
130
Реакции
6
Баллы
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?
 
This means element was not found by attribute. Not the problem accessing instance property.
Where are you using this code? What element with?
 
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.
 
Последнее редактирование:
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.
 
We should ask @lokiys I think..., he is C# guru)
 

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