none
Problem Changing size of scrollbars using SystemParametersInfo(SPI_SETNONCLIENTMETRICS

    Question

  • On startup of  my app, I am changing the size of scrollbars so they are touch-friendly:

    • UnsafeNativeMethods.SystemParametersInfo(Constants.SPI_SETNONCLIENTMETRICS, metrics.cbSize, pncmetrics, 0);

    I am fairly certain the setup/marshalling of the data is correct because this works fine most of the time.  However, on occassion my app does not start up and I have traced it using the debugger to the aforementioned SystemParametersInfo API call, from which control never returns causing my app to hang.  A reboot of the Win 7 OS seems to be the only way to resolve the problem once it occurs.

    Any ideas what would cause this API call to hang like this (only sometimes)?  I can provide the code for the entire function used to get/set the scrollbar size if anyone thinks that would be useful.

     

    Thanks in advance!

    AndyB

    Wednesday, June 13, 2012 6:46 PM

All replies

  • Hi AndyBachman,

    Welcome to the MSDN forum.

    Can you provide the code for us please? Thanks.

    Have a nice weekend.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 15, 2012 3:26 AM
  • [from which control never returns]

    What do you mean the control does not return? We only can see one method call does not return.

    [causing my app to hang]

    Do you mean the above control is a Scrollbar? And when you try to scroll it, it didn't response to you, and then the whole application hang there, not responding, right? Is this what you meaning? If not, please try to help us clarify it, thanks.

    [A reboot of the Win 7 OS seems to be the only way to resolve the problem once it occurs.]

    Do you mean though end the process and then restart your application, it always cannot work, just after reboot the system, then it can work?

    [Any ideas what would cause this API call to hang like this (only sometimes)?]

    From the description, the SystemParametersInfo does not seemed hang, it is your application other part hang.

    [I can provide the code for the entire function used to get/set the scrollbar size if anyone thinks that would be useful.]

    [this works fine most of the time.]

    I'm afraid it will be hard to repro, maybe we cannot repro this same issue.

    You can choose a way to dump the memory, then we can try to find the clues form there with your code and pdb.

    http://vinaytechs.blogspot.com/2010/01/how-to-get-crash-or-hang-dump.html 

    You can share the dump, codes and pdb through the "skydrive".

    Though I'm interesting into this issue, but if the issue is caused by the SystemParametersInfo function, then this is really not a C# question, this forum will be needed: http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/threads 

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 15, 2012 6:33 AM
  • Thanks for the replies.  I will share the code on Monday when I get back to work.  In the meantime to answer some of Mike's questions, by "control" I do not mean a physical control like the scrollbar but rather a synonym for "execution".  By "hang" what I mean is that I am stepping through the code using the debugger and when I reach the SystemParametersInfo call and hit the "Step Over" button in the debugger, the next line of code is never executed.  This SystemParametersInfo call is part of the startup of my app and since execution does not seem to continue after hitting this line, the GUI is never displayed.  The app is still running (I can see it in the debugger), and if I select to Pause the app via the debugger to see what line of code is being executed it always jumps back to the SystemParametersInfo call.

    And yes, shutting down and re-starting my app does not fix the issue; I have to literally re-boot the Win7 OS to get my app to start up properly.  Then my app will run fine for awhile until I attempt to shut down (which by the way also calls SystemParametersInfo to restore the scroll bar size to its original value).  If shutdown works ok, then the next re-start works too.  But if I run into problems shutting down, then the re-start will not work and I have to resort to the re-boot of the PC.

    I've read some articles mentioning that if you do NOT pass 0 as the last argument to the call (i.e. different values specifying to post messages to other apps), in some cases your app will hang if the messages are not acknowledged, but since I am passing 0 I do not think that is the problem.

    Sunday, June 17, 2012 3:31 AM
  • [By "hang" what I mean is that I am stepping through the code using the debugger and when I reach the SystemParametersInfo call and hit the "Step Over" button in the debugger, the next line of code is never executed. ]

    Maybe there's any logic problem make that path can not be executed if there's an if/switch such statement control it.If there's no judgement statement control, then I would like you just set a breakpoint at that "next line" statement. And do not set breakpoint before it, just let the application execute to there and break, then ensure if that statement can break by the debugger. 

    And I think what we have forgot is the value returned form this API, what the error code when you use the GetLastError when the return value is false?

    I should admit, I have no more ideas, the UI dev forum would give you more export and quick helps: http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/threads 


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 7:50 AM
  • I am writing to check the status of the issue on your side.

    What about this problem now?

    Would you mind letting us know the result of the suggestions?

    If the problem also cannot solved, then please let me know, then I will move your thread to the UI dev Forum, that forum will be more appropriate one for you.

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 20, 2012 6:01 AM
  • On startup of  my app, I am changing the size of scrollbars so they are touch-friendly:

    * UnsafeNativeMethods.SystemParametersInfo(Constants.SPI_SETNONCLIENTMETRICS, metrics.cbSize, pncmetrics, 0);

    Andy,

    If you write the equivalent lines of code in a simple native C++
    console application, can you reproduce the hang on your system?

    Dave

    Thursday, June 21, 2012 8:21 AM
  • I am seeing the same problem. Originally noticed the problem with a C# DotNet project, but once it gets into the hung state, if I kill that process, and write a small C++ native test app, that also hangs in the same place.

    NONCLIENTMETRICS ncm;
    ncm.cbSize = sizeof(ncm);
     
    bool ret1 = ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
     
    bool ret2 = ::SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);

    // never reaches here.

    OS: Seen in both Windows 7 and Windows 8. Both fully patched.
    Build: Debug or Release, doesn't matter.
    From the command line, or in the compiler (vs2012), same result.
    A reboot did fix the problem, although I did save a memory dump.


    • Edited by r.mcgrath.73 Wednesday, October 30, 2013 3:05 PM
    Wednesday, October 30, 2013 2:45 PM
  • I got the same Problem! Someone has a solution or workaround for this problem?

    Monday, December 09, 2013 6:23 PM
  • Hi Mike !

    I'm having the same problem.

    This call never returns :
    SystemParametersInfo(SPI_SETNONCLIENTMETRICS, Marshal.SizeOf(metrics), ref metrics, 0)

    I mean that execution never get back to my code ...

    Did you have any new information about this ?

    Thursday, July 03, 2014 11:06 AM
  • Same problem as you all !

    This call never returns :
    SystemParametersInfo(SPI_SETNONCLIENTMETRICS, Marshal.SizeOf(metrics), ref metrics, 0)

    Windows 7 x64.

    I mean that execution never get back to my code ...

    Except my code is when exiting my app, so as a result my app closes but the process never quits.

    Did someone had any new information about this ?

    Thursday, July 03, 2014 11:08 AM