locked
Large C# forms app much slower in Win8 RRS feed

  • Question

  • Hello,

    I have a C# Windows Forms app that has many buttons on many tabbed pages, where each button corresponds to an adjacent text box.  I type whatever I want into the text boxes and when I click a button it merely places the text in the corresponding text box onto the clipboard, and that's all the application does.  I originally wrote it using VS2010 Pro on Win7-64bit Pro and it worked perfectly.  However, I then downgraded to Win 8-64bit Pro and the same executable would no longer run properly in that when I clicked a button it no longer put the text on the clipboard.  Along with Win 8 I also upgraded(?) to VS2012 Pro, so I merely recompiled the program in hopes that would fix the problem.  However, when I tried to run it I got a runtime stack overflow in the automatically-generated "InitializeComponent" function, which never occurred before.

    My application is big - there are over 66 thousand statements in the "InitializeComponent" function.  Although I should not have to manually modify an automatically-generated file I went ahead and moved those 66K statements out of InitializeComponent, split them into ~10K groups, placed them into 6 separate functions.  I then called those 6 functions from InitializeComponent, the stack overflow problem went away, and the application once again worked.  Then I noticed another problem:  In the Win7 version the application took about 10 seconds to startup but in the Win8 version it now takes over 1 minute.  I'm using a 3.07GHz i7 CPU with 12GB RAM, a 256GB primary SDD with plenty of unused space on it, and a secondary HDD with plenty of unused space on it to.

    So, I have these questions:
    1. Why wouldn't the original Win7 .exe run properly on Win8?
    2. After recompiling with VS2012 why did I start getting stack overflows in the InitializeComponent function?
    3. Is there some way to increase the allowed stack space?
    4. Why does the application now take such an unreasonable amount of time to start up?

    Thanks,
    Ray Mitchell

    • Moved by Mike Feng Monday, April 22, 2013 8:45 AM
    Saturday, April 20, 2013 3:43 AM

All replies

  • There should be nothing needed for porting an application from Windows 7 to Windows 8

    "However, I then downgraded to Win 8-64bit Pro"

    Why did you change your program to do that?

    Be aware I reply to you based on the header of your question, not your text. The header is how people see it. 

    Be aware if the problem is about the same executable the question is more a system admin question.

    http://social.technet.microsoft.com/Forums/en-US/categories


    Success
    Cor



    Saturday, April 20, 2013 8:50 AM
  • Regarding slow startup, try restoring the generated body of InitializeComponent and then add an attribute:

    [MethodImpl(MethodImplOptions.NoOptimization)]
    private void InitializeComponent()
    . . .

    • Edited by Viorel_MVP Saturday, April 20, 2013 4:45 PM
    Saturday, April 20, 2013 4:45 PM
  • There should be nothing needed for porting an application from Windows 7 to Windows 8

    "However, I then downgraded to Win 8-64bit Pro"

    Why did you change your program to do that?

    Be aware I reply to you based on the header of your question, not your text. The header is how people see it. 

    Be aware if the problem is about the same executable the question is more a system admin question.

    http://social.technet.microsoft.com/Forums/en-US/categories


    Success
    Cor



    Cor,

    I agree totally that nothing should be needed to port a Win7 program to Win8, and that was one of my questions.  As far as I was concerned the same executable should have just worked on either OS.  But under Win8 it would no longer place anything on the clipboard, which is why I rebuilt it.  After I did I began getting the stack overflows.  After I kluged the auto-generated source code the application slowed way down.  I don't know how I could have titled my posting any better without making it much more verbose since there were several issues involved.  I merely chose the issue I have not been able to resolve for the topic.  If your also asking why I switched to Win8, my answer is that I always move to the newest OS when it comes out just to keep up to date with the latest technology, plus from the reports I read it supposedly runs somewhat faster, but that's obviously not always true!

    Ray

    Saturday, April 20, 2013 6:47 PM
  • Regarding slow startup, try restoring the generated body of InitializeComponent and then add an attribute:

    [MethodImpl(MethodImplOptions.NoOptimization)]
    private void InitializeComponent()
    . . .

    Hi Viorel_,

    Thanks for the suggestion, but the change makes no difference.  After restoring InitializeComponent to its original condition and adding the code you suggest above, I'm back to getting the stack overflow after about 1 minute of "thinking".  Just for test purposes I copied the .exe I created on Win8 using VS2012 over to my Win7 machine, it started up in less than 5 seconds, and it worked perfectly.  The original .exe that worked on Win7 also starts up quickly on Win8, but it just doesn't copy the data to the clipboard under Win8.

    Ray

    Saturday, April 20, 2013 7:17 PM
  • Ray,

    I did not ask why you switched to W8. 

    However, why not start with the first problem (the Clipboard) and ask help in the forum for your program language.

     

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads

    Normally it should be no problem, so you should have done something very special.


    Success
    Cor

    Sunday, April 21, 2013 11:10 AM

  • However, why not start with the first problem (the Clipboard) and ask help in the forum for your program language.

     

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads

    Normally it should be no problem, so you should have done something very special.


    Success
    Cor

    I did not use the language forum you provide the link to above because on that forum it specifically states that it should not be used for Windows Forms questions  Mine is a Windows Forms application.

    Ray

    Sunday, April 21, 2013 6:54 PM

  • I did not use the language forum you provide the link to above because on that forum it specifically states that it should not be used for Windows Forms questions  Mine is a Windows Forms application.

    Ray

    That is right, but this forum is for VB, C++, F#, VBS, VBA, and also C#.

    To solve your problem you should have to show the code around the clipboard. Be aware contributors of this forum from the languages above and also some from C#. Therefore why not take the forum where only the C# experts live?

    That sentence is meant when your question is in particular around the Windows forms or components (including the component) but giving you this link does not help you much I assume.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx



    Success
    Cor


    Monday, April 22, 2013 10:55 AM
  • Hi,

    Have you try to update .NET on Windows 8?

    http://support.microsoft.com/kb/2750149


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, April 24, 2013 2:48 AM