我想在我的程序的主線程上使用STAThread屬性。但是,Visual Studio稱它無法找到它。我已經嘗試引用必要的程序集並使用適當的命名空間,但它無法找到它。爲什麼我不能在C++/CLI中使用STAThread屬性?
編輯:
我已經能夠去後手動創建與 的ApartmentState到STA線程成功運行。我認爲這相當於設置線程,無論它是主線程,但不完全是因爲我正在創建另一個線程。任何人有另一種方式來做到這一點。
下面是代碼:
void threadStart()
{
Application::Run (gcnew GraphicsForm());
}
[System::STAThread] // This will not work!
int main(array<System::String ^> ^args)
{
Thread ^t = gcnew Thread(gcnew ThreadStart (threadStart));
t->ApartmentState = ApartmentState::STA;
t->Start();
return 0;
}
CTRL + F'STAThread' http://smellegantcode.wordpress.com/2008/06/07/ccliwpf/ – 2014-09-13 03:40:33
我試過了。它不起作用。 – jax 2014-09-13 03:46:48
什麼是錯誤信息? – 2014-09-13 05:29:38