SIGN UP MEMBER LOGIN:    
ARTICLE

Cross Thread Operations in C#

Posted by Ajmal Amirzad Articles | C# Language July 14, 2011
When you will work with threads and want to access a control on another thread then its post will solve your problem.
Reader Level:
Download Files:
 


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:

1.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.

4.JPG
 

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks ajmal, Mindcracker community is welcome you in our family. thanks for contribution, waiting for your some good and useful articles.

Posted by Dinesh Beniwal Jul 14, 2011

Well. Before posting this article, i was hesitant that whether you all will like my articles or not. But yeah, i have to say that you all have given me a great support. Inshallah i will begin to write regularly for MindCracker Community.

Posted by Ajmal Amirzad Jul 14, 2011

Great Article

Posted by Dea Saddler Jul 14, 2011

Nice article. Ajmal

Posted by Rohatash Kumar Jul 14, 2011

Welcome Ajmal Good Start.... Nice Article

Posted by Manish Tewatia Jul 14, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor