473,804 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STA Thread Appartment

35 New Member
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 STAThreadAttrib ute 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 7397
PulkitZery
35 New Member
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 STAThreadAttrib ute 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.Threa d.CurrentThread .SetApartmentSt ate(Threading.A partmentState.S TA)

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 Recognized Expert Specialist
My first step would be to check that all your references are correct.
Jun 30 '07 #3
kenobewan
4,871 Recognized Expert Specialist
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
2185
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 block and ensuing output. Seems like the output should be all interleaved and of course it's not. Running Python 2.2 from ActiveState on Windows XP (also doesn't work on Windows 2000). Thanks in advance! adeger
4
2898
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 know of WxPython but I don't know if I can create a WxPython window, use gl rendering code in it and then put widgets on top of that...
7
2707
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 that. Problem is that when program is started many threads are created (see output section), when only two should be running at any time. Can you please help me to identify me where the problem is? Best regards
4
5437
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
5
2834
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 references to it. But what about threads? If I start a new thread that only does 1+1, is it garbage collected after that? If so, do all threads get garbage collected eventually that are 'done'? And if not, why not? Are there references to the thread that...
7
1774
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 of parent thread. 2) Fire event from the parent thread to child thread. To keep the child thread active, i tried different means including while(1){ application.DoEvents()} but seems that it is not working. I am unable to make it work.
9
3079
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 System.Threading.ThreadInterruptedException System.Threading.ThreadStateException to see if I could get more information about why the thread stops running but that code is never executed. Any ideas on how I can debug this?
1
1080
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 highly appreciated. One bedroom appartment, 35 west,kitchener very clean, Near to amenities,
0
1030
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 request. I have this code to launch my application. But it is giving "Class Not registered" error in InitializeComponent of form which has ActiveX control. My application is working perfectly when I am launching this without any
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.