.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

calling thread must be STA, because many UI components require this

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :WPF
Hi all,             I created a simple WPF Application to display a Message. public Window1()         {               InitializeComponent();                              }           public void set(string s)         {                           Msg.Content = s; // Label         }   A Service will send a message for every five minutes. How can I access the set() function from that service?        

View Complete Post

More Related Resource Links

InvalidCastException when calling JavaScript from C# control using a second thread.

Original Issue: I need to be able to call functions in the JavaScript of an HTML page (not ASP.NET) from a C# object embedded in that page.  The c# object has to be .NET 2 level. So I created a C# DLL assembly in VS 2010 which contains a class called NoUIControlClass. set the target framework to .NET 2.0 and made sure to check "Make assembly COM-Visible".  I also signed the assembly so it would have a strong name so I could install it in the GAC.  So far so good. Here is the batch file I run after the project is built to register the control and place it into the GAC: copy "C:\Users\x\Documents\Visual Studio 2010\Projects\NoUIControl\NoUIControl\bin\Debug\NoUIControl.dll" C:\Exploration\NoUIControl C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm NoUIControl.dll /unregister C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm NoUIControl.dll NoUIControl.dll C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\v7.0A\Bin\gacutil.exe /u NoUIControl.dll C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\v7.0A\Bin\gacutil.exe /i NoUIControl.dll This works and all is good.  Next I've turned the security level in IE all the way down for intranet and trusted sites.  Just to make sure that doesn't get in the way.  Here is the HTML file I serve from the web server. <html> <head

The calling thread cannot access this object because a different thread owns it.

this is my code I want to put the win.show in another thread but win object in the main thread. because I need to do some verification to the win.content in main thread when the win ui is refreshing in another thread. however, I hit the exception The calling thread cannot access this object because a different thread owns it.   namespace ConsoleApplication1 {     public delegate void AsyncDelegate();     public class Program     {                 [STAThread]         static void Main(string[] args)         {             Window win = new Window();                        AsyncDelegate call = new AsyncDelegate(()=>win.Show());             call.BeginInvoke(null, null);                     }             }     }

Closing a WPF form from another thread?? The calling thread cannot access this object because a diff


I have a WPF form with a Close buttom which just does


I also have a public method in this WPF form which goes like this

public void doClose()

doClose() is supposed to be called by other classes but I keep getting this runtime error when this method is called:

The calling thread cannot access this object because a different thread owns it.

Please tell me how to solve it.



1 + 1 = 3

Unable to cast COM object error when calling COM from .NET C# worker thread


I'm having an issue calling a COM object function from .NET C# client program. The COM object is written in C++ unmanaged. The problem only appears when I'm calling from a worker thread, it works fine if I call it from the UI thread. This is the error:

Unable to cast COM object of type 'gvAgileFileReaderLib.gvAgileFileReaderClass' to interface type 'gvAgileFileReaderLib.IgvMpiRead'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{616B5C39-C7FB-4C8C-85D4-27559DD83304}' failed due to the following error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

I have tried the following methods but all of them fails:

1) Create the COM object on UI thread, and call its function via its interface (IgvMpiRead) in the worker thread

2) Create the COM object on the worker thread & access its function from worker thread

3) Tried with worker thread set to STA & MTA

I need to use the COM function is a worker thread to prevent a long processing from holding up my UI, but it just doesn't work when I try to call the COM function inside the worker thread.

The weird thing is that doing the same from a unmanaged C++ client works fine (I can create the com object on UI, and then call its function from worker thread). Is this problem caused by inter

Dynamic controls added at runtime, threading, The calling thread cannot access this object because a




My problem is on load I initialise a new thread. This thread create a new control then tries to add the control to a stackapnel and the error I receive is -

The calling thread cannot access this object because a different thread owns it.

Heres is my code e-




t = new

Sys.require + wcf svc/jsdebug


using Sys.require i do this:


however if i need to call a wcf service aka Sys.scripts.WebServices namespace.

I need to include the svc file javascript proxy after this call:
    <script src="/Modules/ShoutBox/ShoutOutService.svc/jsdebug" type="text/javascript"></script>

placing this before sys.require gives me javascript errors that certain objects don't exist yet.. since sys.require dynamically downloads javacript libraries.

is there another approach I could use o wait till all
Sys.scripts.WebServices  namespace is down before retrieving my wcf proxy classes?

I would like to not rely on "inclusion" sequence .. hoping api already exists.

connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly.


I dont have the SQL EXPRESS installed instead I have SQL Standard Edition.

 I have two SQL Server instances installed.

 1- UserLT (this is sql 2000)
2- UserLT\SQL2005 (this is SQL 2005 named instance)

But when i try to add a database to my VS website project I get the following error:

Connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=4925

I went in Tools>Opetions>DataBase tools>Data Connection>Sql Server Instance Name (blank for default)

and changed the "SQLEXPRESS" to "USERLT\SQL2005".

But I still get the same error message. Any ideas how i can resolve this issue?

require Video tutorial for Composite server control and rendered server control


hi guys

i am new to forum and technology so please go easy

according to what i read from web there 3 types of custom server controls

1. composite



i found video tutorial to create and use superclass custom control in your project (extending dropdown control functionality)

i am trying to search video tutorial for other 2 types .please help me.

Calling webservice from the server


I have a sample web service and aspx file. I deployed them to an existing website that contains classic asp files.

web-service: --- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; [WebService(Namespace = "http://localhost/MyWebServices/")] public class MembershipRegisWebService : System.Web.Services.WebService { public MembershipRegisWebService () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string HelloWorld() { return "Hello World."; } }

aspx.cs file: --- using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services; public partial class CallWebService : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { MembershipRegisWebService mrWs = new MembershipRegisWebService(); Response.Write("Calling web service:" + mrWs.HelloWorld()); } }

It runs locally, but it shows an error when running it from the server:

Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the follow

Thread Performance: Resource Contention Concurrency Profiling in Visual Studio 2010


Visual Studio 2010 includes new resource contention profiling features that help detect concurrency contention among threads. We walk through a profiling investigation to demonstrate how you can pinpoint and fix resource contention problems in your code.

Maxim Goldin

MSDN Magazine June 2010

Thread Diagnostics: Performance Tuning with The Concurrency Visualizer in Visual Studio 2010


Understanding performance bottlenecks in multithreaded apps used to require significant instrumentation and analysis by expert developers. The Concurrency Visualizer in Visual Studio 2010 significantly reduces the burden of parallel performance analysis.

Hazim Shafi

MSDN Magazine March 2010

CLR Inside Out: Thread Management In The CLR


Getting the performance you want in concurrent applications is not as straightforward as you might think. See how common threading issues can affect your application.

Erika Fuentes and Eric Eilebrecht

MSDN Magazine December 2008

Editor's Note: new Thread(ReadEditorsNote).Start(); yourAttention.WaitOne();


Introducing the issue, Howard Dierking points out that you can't simply parallelize your code blindly if you expect to truly reap the benefits that parallelism promises.

Howard Dierking

MSDN Magazine October 2008

Pooled Threads: Improve Scalability With New Thread Pool APIs


The new threadpool APIs in Windows Vista and in the upcoming Windows Server 2008 provide advances that even native Windows developers can benefit from.

Robert Saccone

MSDN Magazine October 2007

Concurrent Affairs: Build a Richer Thread Synchronization Lock


In my last column, I showed the various thread synchronization mechanisms employed by the Microsoft® . NET Framework (see Concurrent Affairs: Performance-Conscious Thread Synchronization). I then examined the performance characteristics of all these mechanisms and determined that the Interlocked methods performed the best because the calling thread never has to transition to kernel mode.

Jeffrey Richter

MSDN Magazine March 2006

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend