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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Previous result of a method call is remembered. Is this related with JIT compiler?

Previous result of a method call is remembered. Is this related with JIT compiler?

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 3 Posters 1 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.
  • B Offline
    B Offline
    bin_bin1
    wrote on last edited by
    #1

    In my code, I use a static method of a class. For example, class name is ABC. The static method name is GetService(). I called the ABC.GetService() twice. The first time it returns null, because the ABC service is not available at that time. However when I call the method the second time, it should return the service, because the service is available already. but the code still retunrs null. If I put a break point before the second time I call the function. I can use code to see the ABC.GetService() returns the service. It seems to me that the code remember the previous result and used it again when it should not. Is there a way to resolve this issue. Any suggestions are greatly appreicated. Best Regards Bin

    C D 2 Replies Last reply
    0
    • B bin_bin1

      In my code, I use a static method of a class. For example, class name is ABC. The static method name is GetService(). I called the ABC.GetService() twice. The first time it returns null, because the ABC service is not available at that time. However when I call the method the second time, it should return the service, because the service is available already. but the code still retunrs null. If I put a break point before the second time I call the function. I can use code to see the ABC.GetService() returns the service. It seems to me that the code remember the previous result and used it again when it should not. Is there a way to resolve this issue. Any suggestions are greatly appreicated. Best Regards Bin

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I suspect your code is broken. The best way to write code like this, is to make your static property check if the return value is null, and if it is, try to populate it, before returning it. Obviously, if you want us to tell us what's wrong with your code, you need to post it.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      B 1 Reply Last reply
      0
      • C Christian Graus

        I suspect your code is broken. The best way to write code like this, is to make your static property check if the return value is null, and if it is, try to populate it, before returning it. Obviously, if you want us to tell us what's wrong with your code, you need to post it.

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        B Offline
        B Offline
        bin_bin1
        wrote on last edited by
        #3

        Thank you very much for your reply. The first time when the function is called. The value is supposed to be null. I don't want to populate the value at that time. I cannot post the code here. It is a very big project. The service is SharePoint shared service. In the beginning, the service is not available. I ran psconfig.exe to create the shared service. I will try to repro this with some simple example. Thank you very much Bin

        C 1 Reply Last reply
        0
        • B bin_bin1

          In my code, I use a static method of a class. For example, class name is ABC. The static method name is GetService(). I called the ABC.GetService() twice. The first time it returns null, because the ABC service is not available at that time. However when I call the method the second time, it should return the service, because the service is available already. but the code still retunrs null. If I put a break point before the second time I call the function. I can use code to see the ABC.GetService() returns the service. It seems to me that the code remember the previous result and used it again when it should not. Is there a way to resolve this issue. Any suggestions are greatly appreicated. Best Regards Bin

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          If you get a different result running and stepping through some program code, I always suspect either a timing issue that depends on external stuff or the optimizer settings when you compile. As to why there's a problem, as mentioned, without code who knows.

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          1 Reply Last reply
          0
          • B bin_bin1

            Thank you very much for your reply. The first time when the function is called. The value is supposed to be null. I don't want to populate the value at that time. I cannot post the code here. It is a very big project. The service is SharePoint shared service. In the beginning, the service is not available. I ran psconfig.exe to create the shared service. I will try to repro this with some simple example. Thank you very much Bin

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            You can't post the code to a property ?

            Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

            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