locked
82% cpu usage on this function RRS feed

  • Question

  • User1080785583 posted

    ExecuteAction(() => result = func(), attemps, application, rethrowException);

    What does this even mean?

    Wednesday, April 22, 2015 12:25 PM

All replies

  • User753101303 posted

    Hi,

    Some more context could help. See to which class this method belongs (you could also use "view definition") and check the documentation for this class.

    It seems basically to try some code and try again few times if it fails...

    Edit: a search on both "ExecuteAction" and  "attemps" words, gave me https://msdn.microsoft.com/en-us/library/hh675296.aspx that looks similar but it would be easier to know the class name.

    Wednesday, April 22, 2015 12:48 PM
  • User1080785583 posted
    protected T Execute<T>(Func<T> func, ExceptionApplications application) where T : class
    		{
    			return Execute(func, 1, application, true);
    		}
    
    		protected T Execute<T>(Func<T> func, ExceptionApplications application, bool rethrowException) where T : class
    		{
    			return Execute(func, 1, application, rethrowException);
    		}
    
    		protected T Execute<T>(Func<T> func, int attemps, ExceptionApplications application, bool rethrowException) where T : class
    		{
    			T result = null;
                //ExecuteAction(func,attemps,application,rethrowException);
                //var myType = (Action)func<Action>(typeof(Action), "foo");
    		    //var funck = func.Invoke();
    			ExecuteAction(() => result = func(), attemps, application, rethrowException);
                //return funck;
    			return result;
    		}

    for some reason it looks like the developers who wrote this were trying to use generics too much. im curious how i can simplify this.

    Wednesday, April 22, 2015 1:25 PM
  • User-1910946339 posted

    At first glance this looks like an infinite loop to me (maybe a stackoverflow might stop it running forever Smile ).  Have you used the debugger to single step through the code?

    Wednesday, April 22, 2015 9:03 PM
  • User753101303 posted

    And it is used  for which kind of operations? Is this used directly from the application code or does it support some other retry layer? If related to something particular a specialized forum might be better (could it be what is used for Azure retries?)

    Thursday, April 23, 2015 3:55 AM
  • User1080785583 posted

    It is used for all data access operations. Example call is as follows:

    ClientService<ILoanSync>.UseFunc(
    item => item.Save(Guid.Parse("gnarlyGuid")));

    which calls this method...

    public static TResult UseFunc<TResult>(Func<T, TResult> codeBlock)
    {
    return UseFunc(codeBlock, TimeSpan.Zero);
    }

    which calls this method...

    public static TResult UseFunc<TResult>(Func<T, TResult> codeBlock, TimeSpan operationTimeout)
    {
    return Instance.UseFuncInstance(codeBlock, operationTimeout, 3);
    }

    which calls this method...

     private TResult UseFuncInstance<TResult>(Func<T, TResult> codeBlock, TimeSpan operationTimeout, int attempts)
            {
                IClientChannel proxy = null;
                bool success = false;
                
                TResult result = default(TResult); 
                    //channelFactoryLock.EnterReadLock();     // it's enough to have only ReadLock, because it will provide multiple reading access, and ChannelFactory creation goes through Interlocked.CompareExchange
                    proxy = (IClientChannel) ChannelFactory.CreateChannel();
                    proxy.Open();
                    
                        result = codeBlock((T) proxy);                     
                        proxy.Close(); 
                        success = true;
                    } 
    
                return result;
            }

    then expensive here - codeBlock((T) proxy ),

    Thursday, April 23, 2015 2:08 PM