Erratic behavior when running 2 winforms apps

Hello All,

I am testing a winforms application that will start a thread for a new winforms application and will allow the first application to run tests against the second in WinCE 5.0.

If I run two winforms apps at once, it seems to cause erratic behavior. I am using cf 2.0 and at first I tried a console app as the initial application with a winforms app being controlled and that was worse. The test UI app is mimicked closely to James McCaffrey and his testrun501 example:

http://msdn.microsoft.com/msdnmag/issues/05/01/TestRun/default.aspx

This original app worked fine in desktop winforms as that supports the STATHREAD attribute (single thread apartment) which cf 2.0 does not.

Any thoughts or suggestions would be greatly appreciated :)

Bob Hanson




Answer this question

Erratic behavior when running 2 winforms apps

  • Rubal Jain

    You can not have two message pumps on different threads in a single process as they would fight with each other causing "erratic behavior". You should start test application in a separate process and test it using normal windows API/messages (e.g. FindWindow).

    Another thing to try is to create a console application, then create a thread which would do testing. Then, on a main thread, create appdomain and launch tested application on it. This way only tested application would have the only message pump.

    However, I'm not sure that would work and separate process with Windows API/messages might be the only way to go.



  • Siegfried Van Haelst

    It appears you forgot to describe the "erratic behavior". Also, you’re probably starting a process with second application, not a thread. Is that right



  • Jeff Putz

    You can not. Obviously desktop framework somehow creates only one message pump if you using STATHREAD, but NETCF won't do that. Attribute is just a tip of the iceberg, code which actually processes that attribute is simply not implemented.

    Please try console test driver of use separate process and windows API/messages, that’s the way GUI applications been tested for years. It would work with native application as well.



  • Subhosh

    Thanks Ilya for your help :)

    Have a great day :)

    Bob Hanson



  • the_developer

    I'm not quite sure this attribute (which is generaly only relevant to COM setup) has anything to do with that. Are you using any COM/ActiveX objects at all



  • levyuk1

    I am sorry for the vague posting. What I am running into is that Windows CE 5.0 (Compact Framework 2.0) does not support STATHREAD attribute for using a single-threading apartment. The application is accessing the WinCE 5.0 winforms UI via the Invoke method but this requires the use of the single-threaded apartment.

    I am not sure if there is a way to remedy this or not.

    Thanks in advance for any thoughts or ideas :)

    Bob Hanson



  • Stefan Mueller

    Yes, thanks this makes sense. I did find information in a C# book to this affect and they of course suggested the use of the STATHREAD attribute. This works for the .Net framework 2.0 just fine but I can't do this for cf 2.0.

    Any thoughts on how I could regulate this behavior in the cf 2.0 environment

    Thanks for your replies :)

    Bob Hanson



  • Vaassu

    I have a WinCE 5.0 app starting a thread that starts a WinCE 5.0 Winforms app for the sake of setting and getting winform UI control properties to use for simple UI testing. If you go to the link I mentioned in my first post, I started with that source code.

    Thanks for your help :)

    Bob Hanson



  • Erratic behavior when running 2 winforms apps