M
Morten Herman Langkjaer
I have an application written in C#, that is a windows application. in the
application there is a treeview that allows drag-n-drop functionality. To
enable drag-n-drop, the main thread of the application hasto be a single
threaded apartment, so i marked my main method with the [STAThread] attribute.
When starting my application, i received an exception that the main thread
should be Single threaded apartment, and to my surprise, i found that the
Thread.CurrentThread.GetApartmentState() operation returned MTA.
I tried to create a new project for testing this issue, only having a single
program file, instead of a large project. To my surprise, the new test
project had STA for the current thread, when i started debugging the main
method.
After that i tried to copy all my code files into my new test project, and
then debug again, and then my application suddenly had STA on the main
thread. Since my demo project was located in the "my documents\visual
studio..." folder, i decided to move the folder containing the demo project,
including the product code, to the folder structure of my configuration
management system. After moving the project, i tried to debug my demo project
again, and once again, i was surprised to see that the maain thread now was
MTA again. It was the same source and the same project file, that in a
different location had a different result.
Later i foun out, that if i run the application without the debugger
attached, the apartmentstate is STA, but if i debug, the apartmentstate is
MTA.
Is there anyone that can help me with this issue? could it have something to
do with the fact the debugging causes the Visual studio hosting proces to
execute my application and that it could possibly be startet in a multi
threaded apartment?
I hope somebody can help me, i would really like to debug my application.
application there is a treeview that allows drag-n-drop functionality. To
enable drag-n-drop, the main thread of the application hasto be a single
threaded apartment, so i marked my main method with the [STAThread] attribute.
When starting my application, i received an exception that the main thread
should be Single threaded apartment, and to my surprise, i found that the
Thread.CurrentThread.GetApartmentState() operation returned MTA.
I tried to create a new project for testing this issue, only having a single
program file, instead of a large project. To my surprise, the new test
project had STA for the current thread, when i started debugging the main
method.
After that i tried to copy all my code files into my new test project, and
then debug again, and then my application suddenly had STA on the main
thread. Since my demo project was located in the "my documents\visual
studio..." folder, i decided to move the folder containing the demo project,
including the product code, to the folder structure of my configuration
management system. After moving the project, i tried to debug my demo project
again, and once again, i was surprised to see that the maain thread now was
MTA again. It was the same source and the same project file, that in a
different location had a different result.
Later i foun out, that if i run the application without the debugger
attached, the apartmentstate is STA, but if i debug, the apartmentstate is
MTA.
Is there anyone that can help me with this issue? could it have something to
do with the fact the debugging causes the Visual studio hosting proces to
execute my application and that it could possibly be startet in a multi
threaded apartment?
I hope somebody can help me, i would really like to debug my application.