All Questions
15 questions
3
votes
1
answer
544
views
Is it possible to apply attribute to the generated main method in a top-level application?
C#9 supports top-level statements, but I am curious whether it is possible to apply any attribute to generated main method (STAThread, actually), or I have to use classical approach with Main method.
2
votes
1
answer
1k
views
C# kill all processes started with Application.Run when main form closes
I am starting a bunch of invisible forms in seperate threads from my initial form with
Thread thread = new Thread(() =>
{
var form= new myform();
...
4
votes
1
answer
282
views
Form behaving weirdly when using STA and threads take too long
We're developing a multithreaded game engine in C#, and we got the problem that we need the STAThread attribute (or set our threads to STA manually) to enable drag-and-drop support (AllowDrop can't be ...
0
votes
0
answers
322
views
CLR exception STAThread attribute required for ElementHost in WinForms app
I have a WinForms VB app, using Visual Studio 2010. I am using the WPF DocumentViewer, so it is hosted by the ElementHost control. In my AppMain_Form.Designer.vb, when the follopwing (generated) ...
0
votes
1
answer
2k
views
WPF user control crashes with 'The calling thread must be STA'
The Code Behind of a WinForm is crashing with The calling thread must be STA, because many UI components require this., when trying to create a WPF user control, using myWpfUserControl = new ...
4
votes
3
answers
3k
views
Defining STA: "single thread affinity" or "single threaded apartment"; and how they relate
I'm working with WPF and am reading through materials on STA. Two questions:
1) STA is defined as standing for both "single thread affinity" and "single threaded apartment" by different articles.
...
0
votes
1
answer
241
views
Using SmartThread with STA and event driven enviroment
Hi I have a use case where I am supposed to use C# Web Browser inside a form and get some data from it. However as we know the C# browser runs under STA hence I have created an instance of SmartThread ...
3
votes
1
answer
2k
views
UI freezes when using SystemEvents.UserPreferenceChanged and multiple UI threads
In my C# Windows Forms application there are two threads:
Main Thread (Program.cs)
WorkerClass Thread (STA-Apartment).
When there is long running Task, it freeze/stuck the entire process and No ...
0
votes
1
answer
2k
views
WebBrowser navigating inside a STAThread within a BackgroundWorker understanding
I was struggling finding a good title as I already solved my problem. I just need an explication of how I solved it ... because I am diving into stuff I just discovered today and it may not be clear ...
4
votes
1
answer
1k
views
Unable to set WinForms clipboard in unit test
I'd like to populate the Forms.Clipboard with text from a NUnit test.
The first problem I encountered was that the Clipboard must be used in STA mode. I found the solution (NUnit 2.5.x+) to set the ...
0
votes
1
answer
558
views
STA thread in windowapplication
I have a bit of code in my project like shown below,here what is the usage of STA thread ?
What i know about STA is it is Single Threaded Apartment,it is only required when using COM components.And it ...
22
votes
4
answers
14k
views
Why are WinForms applications STAThread by default?
When you create an empty WinForms application with Visual Studio, the template has the STAThread attribute in the main application class.
I have been reading some docs about it, but I'm not sure if ...
2
votes
1
answer
541
views
A STA threading mode thread also blocks the winform UI thread?
I am using a STA COM object from a back ground thread, one of the COM object's a method will block, when i call it from a new thread which is in STA threading mode since the COM object's mode is STA, ...
0
votes
1
answer
309
views
how do I delay instantiation of the main form until responded to an event in a WinForms app?
Some background:
I get the following exception in my code below.
ThreadStateException : ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is ...
5
votes
1
answer
5k
views
WPF with Windows Forms - STAThread
I am a newbie to WPF and have a couple of questions about WPF and Windows Forms integration.
I have an existing Visual C# Windows Forms application. I would like to integrate it with a WPF window, ...