How can I write an extension method for an existing method like :
static class Extensions { public static void RunAsThread(this Action func) { Thread t = new Thread(delegate() { try { if (func != null) func(); } catch (ThreadInterruptedException tie) { } catch (ThreadAbortException tae) { } catch (Exception ex) { Logger.LogDebug(ex); } }); t.Start(); } } is there any way that i can run this methods perfectly in the way i wanted
class WorkingClass { public void Work() { //Works fine ((Action)DoSomething).RunAsThread(); //Works fine Extensions.RunAsThread(DoSomething); //But I really need this to work DoSomething.RunAsThread(); } private void DoSomething() { //Do Something } } I really wanted to make DoSomething.RunAsThread() work. I tried to change "static void RunAsThread(this delegate .... or this Delegate)". Could not do it properly. Is there any work around for that? Is there any way for that?
DoSomethingisn't anAction. In certain contexts, the compiler can create anActionfrom it, but this isn't one of those contexts.