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

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

cross thread problem

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :.NET Framework


Im using vs 2010 to try and make an application. It uses multi threading and im trying to change a label on my main form from within the threads but im getting this error : Cross-thread operation not valid: Control 'log' accessed from a thread other than the thread it was created on.

Ive read lots of articles on the web about delegates etc but its too confusing for me :(

Can anyone explain it to me please in newbie language ?

Thanks in advance.


View Complete Post

More Related Resource Links

How to Solve Cross-thread operation not valid: Control " accessed from a thread other than the threa

I have a thread... like Dim a As new Threading.Thread(Address Of generate) Dim WithEvents lst As New ListBox()   Form_Load() Me.Controls.Add(lst) lst.SetBounds(100,100,150,80) End Sub   Button1_Click() a.Start() End Sub   Sub generate() Dim i As Integer For i = 1 To 10 lst.Items.Add(i) Next End Sub   When i run this program it results in the above mentioned Exception - Cross-thread operation not valid: Control " accessed from a thread other than the thread it was created on." What is this actually? Why it has been thrown..? Kinda help me please..... Thanx in advance

Sharepoint check-out document cross reference problem

Hi I have a problem with check-outed word document from Sharepoint Services 3.0. After I check-out document from Sharepoint, cross references in Word document stop working. After I click to cross reference (Ctrl+Click to follow link), Word show me warning message: "Some files can contain viruses or otherwise be harmful to your computer...Would you like to open this file". There is two buttons - OK and cancel. After pressing OK nothing happens. I have Sharepoint Services 2003 (clear installation, no custom code), MS Word 2007 and trying .doc file format. I tried this on two Sharepoints and two client computers, but it is the same. I tried http://support.microsoft.com/?scid=kb%3Ben-us%3B925757&x=8&y=9 , but did not help. How can I disable this behavior? Thanks

Security problem with cross database chaining and stored procedures

I have a situation whereby ProcA exists on database A, but ProcA executes about 20 stored procedures scattered across different databases. To further complicate matters some procs that ProcA calls also call other procs in other databases, this then presents the problem of cross database chaining where you can’t really write to a database from a proc that resides in another database. I am wondering how I can get around this problem, I know I can simply let open cross database chaining and the problem will go away, the other option is to create a proxy which is very complicated and wouldn’t work in my environment. Is there any way around the problem.

problem with cross apply query

Hey guys. This is one of the queries pasted from BOL. I'm having problems excuting this query. The problem lies in the CROSS APPLY part. When I copy this query and run it in SSMS, it gives me an error saying 'Incorrect syntax near .' It doesn't like the qs.sql_handle part. If I remove that and pass the actual handle in for some query, it works. Can someone please tell me what I'm doing wrong?????? Also, I've sp1 installed on my SQL Server 2005 Enterprise, just in case if this matters. Below is the query pasted which is giving me problems. Thank you. SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time], SUBSTRING(st.text, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st ORDER BY total_worker_time/execution_count DESC;

Visual Studio 2008 Cross Reference Problem


Hi to all

I got following warning when I opens my solution...

Warning 1 There is a circular reference involving the import of file "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets". This file may have been imported more than once, or you may have attempted to import the main project file. All except the first instance of this file will be ignored. EM.ShoppingCart

"There is a circular reference involving the import of file "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets". This file may have been imported more than once, or you may have attempted to import the main project file. All except the first instance of this file will be ignored."

I got this error after my VS 2008 crashed three times and after every crash it got restarted and made backup. So three back ups are made in my solution folder... when I got the above mentioned error I moved all the backups from solution but i cant get rid of it....

Thank you;

Cross-Thread Exception at a WinForms control hosted by the WindowsFormsHost in WPF



I have a WPF Application and inside hosted existing WinForms controls.

In WPF i'm using the 'Dispatcher' with the 'CheckAccess' method to check if invoke is required, in my old WinForms controls i use 'InvokeRequired'.

The problem is, that if one of the WinForms controls gets created but not yet shown (drawn) and the application gets to the line, where it has to invoke, the InvokeRequired property returns 'false' even the code is not running under the Main Thread and so it resumes in a Cross-Thread exception.

The strange thing is, that it works fine, when the control gets visible (drawn) before changing it (in my case by switching to the specific tabpage).


For me it seems as if the 'InvokeRequired' property doesn't work reliable when the WinForms control gets hostet by WPF.


It would be great, if someone has experience with this issue and could help me!





Cross-thread operation not valid


I have .net 1.1 compact framework project, which is now migrated to 3.5 compact framework. The project has lot of cross thread calls. The Project runs perfect in .net 1.1, but fails in 3.5.

I keep getting an error "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on." while executing the following code. _currentForm.Controls.Add((Control)_controlList[0]);

some suggested to set Control.CheckForIllegalCrossThreadCalls=false for the form, but unfortunately compact framework don't support CheckForIllegalCrossThreadCalls property.

Request somebody to help me, by educating on how to handle this situation in .net 3.5 compact framework.

Cross Threading Problem

Private Delegate Sub CCDelegate(ByVal CClient As ConnectedClient, ByVal text As String)

Private Sub MessageReceived(ByVal sender As ConnectedClient, ByVal Message As String)
        Dim data() As String = Message.Split("|"c), x As Integer
        Select Case data(0)
            Case "/CONNECT"
                If GetClientByName(data(1)) Is Nothing Then
                    sender.Username = data(1)
                End If
            Case "/DISCONNECT"
                If clients.Contains(sender) Then
                    For x = 0 To lbClients.Items.Count - 1
                        If lbClients.Items.Item(x) = data(1) Then
                            If lbClients.InvokeRequired <> False Then
                                Me.Invoke(New CCDelegate(AddressOf MessageReceived), sender, Message)
                            End If
                        End If
                End If
            Case Else
                MeterData(Message & vbCrLf)
        End Select
    End Sub
I can't seem to execute this line:


Problem to group radio button across gridview rows

In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:

Regrading Sharpoint 2010 problem and solutions

We can write your question and problem on this blogger.you get ans.use.

This sharpoint 2010 problem solving threads

Hi friend,

you can use this thread to solving problem and solutions.

Virtual Path Problem


 I get the following error on last line below (working on remote host): 'E:\web\sfcascom\ls_admin/uploads/images/001.JPG' is not a valid virtual path,

Note that the slashes go in different directions

I've tried a number of things but nothing seems to work. Thanks-


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Web.UI.WebControls

Imports System.Drawing.Imaging.ImageCodecInfo
Partial Class Protected_imageupload
    Inherits System.Web.UI.Page
    Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        ' Initialize variables
        Dim sSavePath As String
        Dim sThumbExtension As String
        Dim intThumbWidth As Integer
        Dim intThumbHeight As Integer
        Dim sFilename As String = ""
        ' Set constant values
        'sSavePath = "images/"
        sSavePath = Server.MapPath("~/") + "ls_admin/uploads/images/"

        sThumbExtension = "_thumb"
        intThumbWidth = 160
        intThumbHeight = 120

        ' If file field isn?t empty
        If FilUpload.PostedFile IsNot Nothing Then
            ' Check file size (mustn?t be 0)
            Dim myFile As Http

Strange Photo upload problem


I'm working project it's live on shared hosting

we'er uploading photos to a file on the server everything works fine the photo is resized renamed and sent to the folder

the upload page returns the thumbnail and the full size photo it's there all the photos have to be approved by an admin

twice now after they have been approved they disapear I checked the folder they are not there could there be anywhere

on the server they could get hung up before they go into the folder I have it setup so when you delete the data base entry it deletes the photo from the folder othe than that you need to open the folder and delete the photo this has hapened twice now I tried to recreate it with no luck

thaks for your help in advance

ASP.Net Caching problem ??


I'm having a problem with an asp.net 3.0 application using a gridview to display data.  The problem seems to be that despite a brand new .selectCommand being sent to the sqlDataSource, the gridview starts displaying data from *someone else's* query.  For example, user A is logged in and will be working fine until a few page submissions later when the gridview data starts suddenly showing information that belongs to another user. 

This is my first asp.net application, though I've been working with classic asp and ADO for years so I'm used to sending a SQL string and getting back the results from that string.  Apparently there is a complex caching system which is interferring which I do not at all understand so at this point I just want to stop the server from caching any data whatsoever.  Is this possible?

Any and all help will be much appreciated!!

Could some one tell me whats the Problem with this String Manipulation ??? C#.net



I store some values from code behind to a label which is Hidden !

<asp:Label ID="lbl_Hidden" runat="server" Visible = "false"></asp:Label>

and at the page load event i retrieve the value of the label & assign it to a string !

stringvalue = lbl_Hidden.Text;

Now i dont know why this manipulation does'nt work !

I've a character 'A' in the string and i'm unable to replace it with a space !

stringvalue.Replace(A, " ");

Wot do u think abt it ????

RaiseEvent problem


I have a parent page ProdView.aspx and two static UserControls, UC1 and UC2. Each UC is in an Ajax accordion pane and the accordion inside an updatepanel.

UC1 has a Gridview footer with couple of textboxes and a link button that fires an Add Row insert procedure. I want to Raise an event that will rebind the UC2 after the row insert in UC1.

First I created the sub delegate and event in UC1:

  • Public Delegate Sub MyRefresh(ByVal sender As Object, ByVal e As CommandEventArgs)
  • Public Event Refresh_UC1 As MyRefresh

In the same UC1 the Insert procedure that fires the insert and RaiseEvent:

Sub PricingGrid_Insert(ByVal sender As System.Object, ByVal e As EventArgs)
       Dim myConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
       Dim myCom As SqlCommand = New SqlCommand("AddRow", myConn)
       myCom.CommandText = "AddRow"
       myCom.CommandType = CommandType.StoredProcedure


Gridview Enable Selection Problem



I have a gridview with Enable selection and Enable Paging equals to TRUE.

I also set the PageSize of my gridview to 4 so that I only displays 4 rows per page.

The problem is when I click the pager in the bottom of my gridview, my gridview is disappearing and no records appear.

Here is code behind of my gridview:

If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Attributes("style") = "cursor:pointer"

                e.Row.Cells(2).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
                e.Row.Cells(3).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
                e.Row.Cells(4).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
                e.Row.Cells(5).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
                e.Row.Cells(6).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
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