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

C#* SonarQube

Avatar of undefined
Last Comment
dpearson
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo