232 questions
1
vote
1
answer
82
views
Is it correct/necessary to use UnsafeStart to launch a second STA thread to avoid UI context in C#?
Context:
My app has a "Paste" feature which triggers a file copy or move operation for copied/cut files. The code that does the eventual IO is a method within a static helper class and is ...
1
vote
1
answer
139
views
How to verify C functions with array parameters using Isabelle
I am using Isabelle to verify a C program. During the verification process, I used the c-parser install-C-file to load the code, but the following issue occurred:
attempt to cause decay to pointer on ...
1
vote
3
answers
165
views
How to make FileSystemWatcher events run in an STA Thread in a console application?
I'm writing a console application that scans a directory for files and uploads the data in them to a database. The files are a proprietary type that require a specific library that requires the ...
5
votes
1
answer
162
views
If a thread has to be STA in Windows, will it work in Linux or MacOS?
Recently I was upgrading a library to use .NET 6 and .NET 7, and there was some code that was setting the apartment state to STA, but I found out that setting the apartment state is a Windows only ...
1
vote
2
answers
454
views
tcl: how to rebuid foreach_in_collection as proc in tcl
for some reason, I need to rebuild foreach_in_collection (SDC command) as "foreach" in tcl.
here's snapshot code:
proc set_disable_timing { argv } { body ... }
proc get_cells { argv } { body ...
-2
votes
3
answers
3k
views
"The calling thread must be STA, because many UI components require this."
I am trying to get a window to open in plain C#.
I've created, for this, a window constructor (SGFWindow) extending the Window class from System.Windows :
namespace SGF
{
public partial class ...
0
votes
1
answer
537
views
How to take a screenshot from a background thread using WinRT?
I'm having issues with WinRT ScreenCapture blocking/freezing my UI.
My app is looping through selected windows and takes a screenshot of each every few seconds.
Every time a screenshot is taken the UI ...
-1
votes
1
answer
134
views
WPF .Net update Progress Bar while loading Classes
I am creating a WPF MVVM Application where I have a Main Window and different Pages displayed in a Frame. I want to add a Loading Screen with a Progress Bar which updates while the Instances for the ...
0
votes
0
answers
197
views
EFCore add-migration error : Error: The calling thread must be STA, because many UI components require this
Error: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: The calling thread must be STA, because many UI ...
0
votes
1
answer
116
views
How to create a STA thread for F# Asynchronous workflow
I am attempting to write a printed form in F# using WPF controls—-and do so in an asynchronous workflow. Being new to this, I can’t figure out how to place the wpf controls, consumed by the F# ...
0
votes
0
answers
1k
views
Catastrophic failure(Exception HRESULT: 0x8000FFFF (E_UNEXPECTED)) while trying to use MS WebView2 in ASP,NET Web API in production environment
I'm getting 'Catastrophic failure(Exception HRESULT: 0x8000FFFF (E_UNEXPECTED))' run-time error while trying to use MS WebView2 in ASP.NET Web API in production environment (Win10, IIS v.20H2 (OS ...
0
votes
2
answers
391
views
Parallel running Progress Bar "Indeterminate" on Login in WPF
Can someone help me on following problem ?
I want to show a "Progress Bar" that is "Indeterminate = TRUE" while the user is connecting to SSH server. If the the connection to the ...
0
votes
0
answers
113
views
Can a WPF Application be hosted on a thread separate from the UI thread?
I'm working on a project to integrate WPF Windows into a large application written in Visual FoxPro. The project has been progressing for a couple of years with success.
One downside to this project ...
0
votes
1
answer
1k
views
What is STA/MTA vs apartments/free threads vs UI threads/worker threads? Why the name changes?
I am reading Inside COM by Dale Rogerson, and it uses the terms apartment threads and free threads to describe the different types of COM threads.
He also clarifies that these correspond directly to ...
0
votes
1
answer
490
views
B2C Custom Policy LoadUri against a CDN fails to load signin form
We have a B2C with custom policies for sign Up, Sign In and Social login, the base page layout is loaded from a CDN (base.html) our custom page layout is as simple as this:
<!DOCTYPE html>
<...
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.
0
votes
0
answers
42
views
call a method on a still running thread
I have a WPF Application running on a STA thread that I can't seem to close, the Start and the Stop goes through a singleton class, and the idea is use It wherever I want in my project with Context....
2
votes
2
answers
2k
views
How to wait for completion of a call to ExecuteScript on a WebView2 interface in a C++ COM STA
I have an COM STA, that hosts an ICoreWebView2.
I try to get the complete HTML block and I found a documentation to achieve this with a script. Here my code:
hr = m_spWebView->ExecuteScript(L&...
1
vote
2
answers
2k
views
What does 'do' do in an UML Statechart diagram?
I am not 100% sure what 'do' does in an UML statechart diagram.
Is my thinking correct:
If a transition happens, 'entry' will be executed first and then 'do' will be executed.
And if we are leaving ...
1
vote
1
answer
209
views
How can you pump a STA Thread in a non-WinForms assembly?
Hans gives this great answer about pumping an STA thread: https://stackoverflow.com/a/21684059/197229
using System;
using System.Threading;
using System.Windows.Forms;
class STAThread : IDisposable {
...
1
vote
0
answers
618
views
How to use a Switch to switch from Wifi Access Point mode to STA in esp32
I am doing an autonomous car project, I need manual control as well as an autonomous function, so the manual control is done through wifi using "gesture control" and for the autonomous control I want ...
0
votes
1
answer
1k
views
IDE contoller not found in viirtual box
Iam following the tutorial here.
Tutorial Image(IDE controller is shown)
In my virtual box I cannot find the IDE controller mentioned here.
1
vote
1
answer
1k
views
VS 2019 Running MSTest in MTA
We have a legacy application with ThreadPool and WaitHandle. We wanted to write Unit-Tests using MSTest against it. We ran into a problem where by default MSTest runs in STA (Single Thread Apartment) ...
3
votes
2
answers
913
views
Is it possible to await a Thread in C#?
I am in a situation where I have to spawn a new thread manually, so I am able to can call .SetApartmentState(ApartmentState.STA). This means (as far as I know) that I cannot use Task. But I would like ...
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();
...
0
votes
0
answers
390
views
Current thread dispatcher creation fails on new STA thread
I have a Windows service running under the Local System account that analyses XPS documents.
On one machine creating the dispatcher on the analysis thread always fails, but on all the other machines ...
10
votes
3
answers
4k
views
How to run NUnit test in STA thread?
We are in the process of porting a WPF app to .NET Core 3, preview 5.
Some NUnit tests need to run in STA threads. How can this be done?
None of the attributes like [STAThread], [RequiresSTA], ... ...
2
votes
3
answers
3k
views
"The calling thread must be STA, because many UI components require this" exception during unit test
I have a class called OptionsWindow which inherits from Window which is for picking from options in a window. And a Dialog Class which deals with these dialogs. In my test, im trying to mock the ...
0
votes
2
answers
426
views
PowerShell: Launch a script as -Sta and Administrator
I have a .ps1 script that I need to launch in Powershell v2.0. Because of this, I use a shortcut file to launch it in Sta mode:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Sta -File "...
4
votes
2
answers
551
views
Why is Task.Delay breaking the STA state of the thread?
Introduction
This is a lengthy question! You will find some background on the problem at the beginning, then code samples, which have been simplified for representation and the Question after that. ...
-1
votes
1
answer
1k
views
COM thread apartments (STA, MTA) management in C# app process
I'm trying to understand C# thread apartments and have questions:
What exactly apartment is and what it contains?
The Apartment and the COM Threading Architecture
A process can have zero or more ...
0
votes
2
answers
2k
views
.Net Core web application running STA thread
I would like to run GET method in controller in STA mode.
For Web API this worked perfectly:
http://ryanhaugh.com/archive/2014/05/24/supporting-sta-threads-in-web-api/
Can it be translated to .NET ...
0
votes
1
answer
65
views
Opening a new WPF Window before WaitForExit() without making the window stuck
I'm developing a WPF Application. Right now I'm trying to do something like this:
//Print the information about what happened, and open toolbar.
MessageBox.Show("Cannot find the ...
0
votes
1
answer
825
views
C# windows service and STA thread clipboard
After doing some searching, I've come to understand that when creating a windows service application, you can implement STA threads to access the clipboard as follows:
thread th = new thread(...
0
votes
0
answers
564
views
Memory leak in STA thread c#
I am creating an STA thread as I am basically using a UI component within a library that has functionality I want without actually having any UI (exporting tables to Excel).
System.Threading.Thread ...
0
votes
1
answer
177
views
Using non-STA threads in VSTO projects to achieve parallelism?
It's clear that using a VSTO application, the main Office application is running an STA thread, and spawning other STA threads pose no problem (actually they do provide some challenges but we can ...
0
votes
0
answers
216
views
Sending messages to STA thread
I have read little bit about COM threading model: MTA and STA, for example this SO post:
Difference between MTA and STA
There we can read that to communicate with object within STA we need to pump ...
0
votes
0
answers
310
views
Trying to open a new window from a WPF window, I get STAThread exception
I have a wpf project, and I am trying to do a popup style window which is a separate wpf window I wrote. I am trying to do a simple Showdialog as I have done before on several other projects. I simply ...
0
votes
0
answers
388
views
How can I get the chosen file from a FileOpenPicker window in C++ winRT?
I have been able to come up with the following C++/winRT code which "almost works". I created a class with a method that returns IAsyncOperation so that I could use the co_await keyword; the method ...
1
vote
1
answer
309
views
How to call InternetGetProxyInfo from a non "Single-Threaded Apartment" thread from Excel VBA using Win32 APIs
I am working on an Excel VBA program, and at some point, I need the proxy to be used when accessing a specific url, proxy that is computed from the .pac file provided by my company. For that, I intend ...
1
vote
0
answers
507
views
PowerShell 6 ApartmentState
I've seen a few questions on here, but have not seen any response. I have a class file that displays a script progress window and it works fine in PowerShell version 5.1.15063.966 but it fails in ...
0
votes
0
answers
124
views
Updating a UI component using Invoke Async Deadlock
I am using devexpress and their PivotGrid control to build a pivot grid. I don't care about displaying it I have no actual UI displayed, I want the PivotGrid so I can export it.
Therefore I am ...
0
votes
3
answers
1k
views
Hourglass cursor in multithread asnc application
I am trying to implement cursor changing when my application making big issue.
I was trying this
public class CursorWait : IDisposable
{
public CursorWait(bool appStarting = false, bool ...
0
votes
1
answer
178
views
Can SendNotifyMessage be used to get onto the COM STA thread?
I am working on an C++ MFC/COM application (including VBA and .NET code) that needs to execute code on the COM STA thread from another thread.
One way, that works, is to use the PostMessage function ...
0
votes
1
answer
440
views
How to change powershell "pwsh" to STA ApartmentState
I'm trying to port some scripts from poweshell 5.0 to the new pwsh powershell 6 and i've noticed that there is no -sta parameter anymore. How can I set the ApartmentState of pwsh? I can;t find ...
1
vote
0
answers
733
views
zkemkeeper: Real time events not triggering on ASP.NET mvc
I have been going bonkers over this one, I am trying to register the real time events in my asp.net mvc web application. but nothing seems to work.
UserController:
ZkemClient objZkeeper2 = new ...
1
vote
1
answer
543
views
C++ DLL in ASP.NET Core STA thread not invoking callback
I need to control a camera from within an ASP.NET core api and all communication is via a pInvoke dll.
In the docs it explicitly states
To create a user thread and access the camera from that ...
-1
votes
1
answer
328
views
STAThread error in System.Timers.Timer, while instantiating Form with AutoCompleteMode of dropdown set
I have, Windows Form, which have System.Timers.Timer in elapsed event of this timer, I wish to popup a form using ShowDialog(), over there while creating object of that form itself, I am getting ...
15
votes
4
answers
6k
views
Set ApartmentState for async void main
I have a Windows Forms app.
Now I want to use an async method.
Since C# 7.1 I can use an async Main method:
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1
However, now my ...
0
votes
1
answer
397
views
How can I call a function in C++ when I get the WinRT/UWP error 'Activating a single-threaded class from MTA is not supported?'
When attempting to call a single-threaded apartment (STA) function from the "wrong" thread (e.g., Clipboard::SetContent(...)), I see the following message:
Activating a single-threaded class from ...