Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. calling a non static method from a static method in a dll class

calling a non static method from a static method in a dll class

Scheduled Pinned Locked Moved C#
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fred 34
    wrote on last edited by
    #1

    namespace NecRoutines
    {
    public class Invoke
    {
    private System.Windows.Forms.Timer TrzTimer = new System.Windows.Forms.Timer();
    private void TrzInitialize()
    {
    this.TrzTimer.Tick += new System.EventHandler(this.TrzTimer_Tick);
    TrzTimer.Interval = 1000;
    TrzTimer.Enabled = true;
    TrzTimer.Start();
    }
    private void TrzTimer_Tick(object sender, EventArgs e)
    {
    // do something when time elapses
    }

    public static void TrzStart()
    {
       TrzInitialize();
    }
    

    }
    }

       //An object reference is required for the non-static field, method, or property
    

    this is the error message that i get for calling TrzInitialize() during building this DLL program. Consider that TrzInitialize() must be non static because of timer routine definition and TrzStart() must be static to be known for main program. thanks

    N 1 Reply Last reply
    0
    • F Fred 34

      namespace NecRoutines
      {
      public class Invoke
      {
      private System.Windows.Forms.Timer TrzTimer = new System.Windows.Forms.Timer();
      private void TrzInitialize()
      {
      this.TrzTimer.Tick += new System.EventHandler(this.TrzTimer_Tick);
      TrzTimer.Interval = 1000;
      TrzTimer.Enabled = true;
      TrzTimer.Start();
      }
      private void TrzTimer_Tick(object sender, EventArgs e)
      {
      // do something when time elapses
      }

      public static void TrzStart()
      {
         TrzInitialize();
      }
      

      }
      }

         //An object reference is required for the non-static field, method, or property
      

      this is the error message that i get for calling TrzInitialize() during building this DLL program. Consider that TrzInitialize() must be non static because of timer routine definition and TrzStart() must be static to be known for main program. thanks

      N Offline
      N Offline
      n podbielski
      wrote on last edited by
      #2

      You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like

      public static void TrzStart(Invoke instance)
      {
      instace.TrzInitialize();
      }

      No more Mister Nice Guy... >: |

      F 2 Replies Last reply
      0
      • N n podbielski

        You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like

        public static void TrzStart(Invoke instance)
        {
        instace.TrzInitialize();
        }

        No more Mister Nice Guy... >: |

        F Offline
        F Offline
        Fred 34
        wrote on last edited by
        #3

        I got rid of confusion and YOU was the reason, it works properly, so I am still novice.

        1 Reply Last reply
        0
        • N n podbielski

          You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like

          public static void TrzStart(Invoke instance)
          {
          instace.TrzInitialize();
          }

          No more Mister Nice Guy... >: |

          F Offline
          F Offline
          Fred 34
          wrote on last edited by
          #4

          thanks, it works properly I appreciate your knowledge. So I am still a novice.

          N 1 Reply Last reply
          0
          • F Fred 34

            thanks, it works properly I appreciate your knowledge. So I am still a novice.

            N Offline
            N Offline
            n podbielski
            wrote on last edited by
            #5

            Everybody was at some point. Don't worry about that. Glad that could help.

            No more Mister Nice Guy... >: |

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups