473,403 Members | 2,354 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,403 software developers and data experts.

STA Thread Appartment

Hey guys,
I am stuck in a problem very bad. I am using .net Remoting for my project to communicate within the TCP network. And after the process is done I have a function that displays a form (Upload Form) which upload the data file to our server. It used to work fine before I added remoting part into it (to make it able to communicate within TCP network).

The problem is, when my application tries to show the upload form, it throws this exception:
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.

By googling the error I found that I need to set the STAThread attribute right on the Main class. But I don’t know where to add this statement in my form. No matter wherever I add it. It still gives me the error.

Can anyone help me here PLEASE. Thanks very much.

Pulkit Zery
Jun 29 '07 #1
3 7381
Hey Guys,

I am getting this error when my application tries to show a form:
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.
By googling the exception message I found that I have to set the thread apartment to STA, so I added this code into my form_load event:
Threading.Thread.CurrentThread.SetApartmentState(T hreading.ApartmentState.STA)

But it throws the exception: Failed to set the specified COM apartment state.

I did some further research and found that I need to add <STAThread> to the main function. I created a new module and defined my main function and set the attribute to STAThread… But that did not help either and I got the first error message again.

I have no idea why is this happning. BTW this happens only if I use .net Remoting library to communicate in network.

I need to solve it ASAP. Can any one please help me out here. Thanks very much in advance for your help and time.

Thanks,
Pulkit Zery
Jun 29 '07 #2
kenobewan
4,871 Expert 4TB
My first step would be to check that all your references are correct.
Jun 30 '07 #3
kenobewan
4,871 Expert 4TB
Please do not multi post it is against site rules as stated in the FAQs. Thanks.
Jun 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
7
by: Ram | last post by:
Hi, I have two threads, one parent thread containing UI and a child thread waiting for some events from the parent thread. Now, I have two issues: 1) to keep the child thread active till the end...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
1
by: Ali | last post by:
Dear friends, We are leaving canada at the end of march so we are looking for someone to take over our place for 5 months from april 1st to the end of augest.Contract is extendable. Your help is...
0
by: Shahzad Godil | last post by:
VB.net solution with this issue http://dotsystem.biz/Files/Shahzad/ThreadCheck.zip Required Visio 2003. I have one remoting server which is launch Visio activex based application on remote...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.