• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MzU3

Related Code
ForEach Extension method for IEnumerable<T>
Use of Extension methods to hide "infrastructure code"
Generic Entity Framework 4.0 Base Repository
Execute.OnUIThread & Execute.InBackground utility methods
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Null Dot "Operator" Extension Method
Generic Entity Framework 4.0 Base Repository with Paging
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
UnitOfWork Action filter for ASP.NET MVC and nHibernate
StringFormat Extension method for HtmlHelper ASP.NET MVC
Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor
IEnumerable<T> Exist extension method
Custom C# exception class
Email validation with Regular Expression
Reflection dynamically get private fields or properties
Url Validation with Regular Expression
Parsing string to enum, extension method
Method to hash passwords
Number of sealed / unsealed types in the framework
Extension to the HttpClient

Invoke Extension Method

Tired of all Invoke methods? Use this Invoke + Lambda

4
552 1 1 0 0 1

Here is an tiny example of an practical Extension method that will save you a ton of time working with Windows Forms with multiple Threads, it should be possible to easily port this one for WPF if you use that.

public static class ControlExtensions
{
    public static void SuperInvoke(this Control control, Action action)
    {
        if (control.InvokeRequired)
            control.Invoke(action);
        else
            action();
    }
 }

To use this extension method it's pretty simple, Inside your form somewhere example if you want to update example an textbox with some text.

 this.SuperInvoke(() => txtMax.Text = "New text Line" );

Hope this will help some in the future or speed up coding for projects that you don't want to waste to much time with.


Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

extension-method

Mark 'extension-method' tag as 'like'

Mark 'extension-method' tag as 'ignore'

invoke

Mark 'invoke' tag as 'like'

Mark 'invoke' tag as 'ignore'

threading

Mark 'threading' tag as 'like'

Mark 'threading' tag as 'ignore'


 Mugi "Code Contributor"
155
December 01, 2010 12:16 PM
edited December 01, 2010 12:22 PM

Fork

 Invoke Extension Method - Mugi Wednesday 01, 2010 12:16 PM


1 Feedback

Nice method. -  FathomSavvy Tuesday 07, 2011 4:22 PM

You must log in before you can give any feedback


1 Discussion(s)

Newest Oldest
0

I could use this. I like.

link | flag  | Reply

 FathomSavvy
13
Tuesday 07, 2011 4:20 PM


You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010