Well, if you are working with threads and want to access a control that is created in another thread then you will always face a problem saying that:

pic1.jpg

To solve the tiny problem, Here is the solution

First of all start the thread and assign it a method you want to execute it on.

Remember, the method you want to assign to the thread should not contain any parameters.

2.JPG

Now here is the RunLoop method

3.JPG

In the first line we get to know whether the control we want to access is created on the same thread or another thread. If it's created on another thread then it will execute the second line.

In the second line we create a MethodInvoker with the name of AssignMethodToControl which is a delegate that executes a method that has no parameters.

In the third line we invoke the MethodInvoker to the Control.

We have achieved our aim so the method will re-execute and it will loop through condition.

pic3.jpg
 

Mohammad Ajmal Amirzad

Mohammad Ajmal Amirzad

From Afghanistan is software developer since 2008, Currently working with Chemonics International Inc as System Developer having experience in developing softwares for governmental, educational, healthcare, pharmaceutica... Read more

http://www.softlogicaf.com/


'Knowledge' 카테고리의 다른 글

Mutex 클래스  (0) 2018.04.19
Working With Thread Local Storage (TLS) in C#  (0) 2018.04.18
Aborting Thread Vs Cancelling Task  (0) 2018.04.18
Task And Thread In C#  (0) 2018.04.18
[.NET] 텍스트 파일에서 읽기  (0) 2018.04.15

+ Recent posts