473,394 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with Threading

VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog();

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in System.Windows.Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttribute marked on it. This exception is only raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?
Feb 25 '06 #1
3 7760
cnickl wrote:
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog();

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in System.Windows.Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your
Main function has STAThreadAttribute marked on it. This exception is
only raised if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?


Was the call to ofdOpen->ShowDialog from your main thread, or from another?

-cd
Feb 25 '06 #2
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

makes no sense here, it's too late to set the ApartmentState at this point,
note also that _tWinMain is also not the real entry point of this 'WinForms'
application, so it makes no sense either to set the STAThreadAttribute as
suggested by the error message.
All you can do is set the /CLRTHREADATTRIBUTE:STA linker switch.
Willy.

"cnickl" <cn****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog();

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in System.Windows.Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttribute marked on it. This exception is only
raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?


Feb 25 '06 #3
I just realized that the entire structure of code is different when you
convert a VS 2003 solution to VS 2005 compared to starting a new project in
VS 2005. VERY frustrating. I decided to start the project over in VS 2005.
Thanks anyway.

"cnickl" wrote:
VS 2005 / C++ / __gc program (converted from VS 2003)

i have this code in my program:

int found;
String *temp;
this->ofdOpen->ShowDialog();

the last line produces the folloing unhandleld exeption:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in System.Windows.Forms.dll

Additional information: Current thread must be set to single thread
apartment (STA) mode before OLE calls can be made. Ensure that your Main
function has STAThreadAttribute marked on it. This exception is only raised
if a debugger is attached to the process.
However my Main funtion lookes like this:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new fclMain());
return 0;
}

Can anybody explain to me whats wrong?

Feb 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
1
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata =...
0
by: Maxwell Hammer | last post by:
Hope someone can help with a problem I'm having. A python program I wrote terminates with the following traceback. *** start traceback *** Error in atexit._run_exitfuncs: Traceback (most recent...
2
by: hnkien | last post by:
Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code: namespace SchedulerService { public class ScheduleService :...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
10
by: MikeScullion | last post by:
I have set up this thread so my program doesn't hang while I call a cpu intensive bit of code: System.Threading.ThreadStart ThreadEncoderStart = new...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
3
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a...
1
by: JoeSox | last post by:
I have two threads going class guiThread(threading.Thread) class mainThread(threading.Thread) Within the guiThread, I have an instance of class GUIFramework(Frame) in this Tkinter instance I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.