Link to home
Create AccountLog in
Avatar of Natavia Finnie
Natavia FinnieFlag for United States of America

asked on

Remove this useless object instantiation of class in C# or use it -- Help

I am not directly following why I am getting this as a Major Bug from my Sonar scan at both lines where this (new SynchronizationTokenMonitor...) is being called.

Result from SonarQube scan:
Either remove this useless object instantiation of class 'SynchronizationTokenMonitor' or use it.

here is the call that is coming from another method:
 AddSynchronizationTokenToOutboundPages(context);

Open in new window

User generated image
private static void AddSynchronizationTokenToOutboundPages(HttpContext context) {
           
            if (context.Handler != null) {
                if (context.Handler is Page){
                    new SynchronizationTokenMonitor(context.Handler as Page);
                }
                else if (context.Handler is TASK.Web.PageHandlerBase) {
                   new SynchronizationTokenMonitor(((TASK.Web.PageHandlerBase)context.Handler).PageControl as UserControl);
                }
            }
        }

Open in new window


       public class SynchronizationTokenMonitor 
      {

             public SynchronizationTokenMonitor(Page page)
             {
                     if (page != null) {
                          page.PreRender += PagePreRender;
                          page.Load += PageLoad;
                    }
              }

              public SynchronizationTokenMonitor(UserControl control)
             {
                    if (control != null)
                    {
                          control.PreRender += ControlPreRender;
                          control.Load += ControlLoad;                
                     }
              }
       }
        

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer