How To Make Thread-safe Calls To Windows Form Controls

Sep 20, 2011

[URL]

In my program, I created a list of a class that contains 5 picture boxes, a button, a label, an identifier, and some other stuff. I've got roughly 65 of these in this list. I'd be stupid to hard code all that in. The identifier is a 2nd way of identifying which specific location I'm working on.

Anways, all this is created at compile time. Works perfectly fine.

I then manually start a background worker that pings a collection of components. Based off the success of those pings, the picture boxes are enabled or disabled. Basically a proactive way to see if a collection of devices over multiple locations are actually working.

It's the background worker that fails because of thread-safe calls.

Private Sub bgwStatus_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwStatus.DoWork
Dim status As Integer

[Code].....

View 1 Replies


ADVERTISEMENT

Winforms - .NET 2.0 - StackOverflowException When Using Thread Safe Calls To Windows Forms Controls

Sep 22, 2011

I have a Windows Forms app that, unfortunately, must make calls to controls from a second thread. I've been using the thread-safe pattern described on the [URL].. Which has worked great in the past.

The specific problem I am having now: I have a WebBrowser control and I'm attempting to invoke the WebBrowser.Navigate() method using this Thread-Safe pattern and as a result I am getting StackOverflow exceptions. Here is the Thread-Safe Navigate method I've written.

[Code]...

View 1 Replies

Thread Safe Calls On Forms Controls Array

Jun 2, 2012

I am trying to access a dynamically generated Control from a separate thread. But I am always getting a "Stack Overflow Exception" with my code. I am using following code:

[Code]...

View 1 Replies

Datagridview - .net Generalized Thread Safe Windows.form?

Mar 25, 2012

''//begin cross threaded component
Private Sub dBgRIDvIEWNotInvokeRequired(ByVal dBGridViewcomponentname As DataGridView, ByVal dvalue As String)
dBGridViewcomponentname.Text = dvalue
dBGridViewcomponentname.Update()

[code]....

when used is like this CrossThreadedDbGridView(DataGridView1, "TheText") But what if I have lots of member or property to used like this code:

DbGridPapers.ColumnCount = 5
DbGridPapers.RowCount = rc
DbGridPapers.Update()

[code]....

View 1 Replies

Make A Thread-safe Call To A Button On Another Form ?

Jan 30, 2012

I am trying to make a thread-safe call to a button on another form and I cannot figure out how to do it.I have read all of the MSDN documentation on thread-safe calls .

View 10 Replies

Make An Invoke Or Safe Thread Call?

Jun 22, 2010

i got a background worker that has the following code in the do work.... one of the things i want to do is to add rows if theres none available ...but i got an error saying i need to do a safe call thread...i already read about it but im stuck i put control.invoke, but that gives me an error too saying Error 1 Reference to a non-shared member requires an object reference.

[Code]...

View 1 Replies

VS 2008 : Make An Invoke Or Safe Thread Call?

May 27, 2010

i got a background worker that has the following code in the do work.... one of the things i want to do is to add rows if theres none available ...but i got an error saying i need to do a safe call thread...i already read about it but im stuck i put control.invoke, but that gives me an error too saying Error1Reference to a non-shared member requires an object reference.what can i do to add rows safely?

vb.net
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
If DataGridView2.Rows.Item(num).Cells.Item(0).Value = "" Then
Control.Invoke(DataGridView2.Rows.Add(1))

View 6 Replies

VS 2008 : Making Safe Crossthread Calls?

Mar 13, 2012

Imports System.Threading.Thread
Imports System
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.demoThread = New Thread(New ThreadStart(AddressOf Me.ThreadProcSafe))

[code]....

I've been trying to use Microsofts example on their MSDN but I'm getting this error. :

Error1'demoThread' is not a member of 'WindowsApplication1.Form1'.C:UsersAydinAppDataLocalTemporary ProjectsWindowsApplication1Form1.vb89WindowsApplication1

View 20 Replies

Make All Of The Controls Arranged In Windows Form?

Jun 10, 2010

I have a windows form that contains a panel (Hosting panel for X number of panels). The hosting panel AutoScroll property is set to true.I need to create X number of a panels each will have (Lable and three Radio buttons) at run time. The panel controls must be aligned.So I created a loop in my form load event to add the X number of the panels on the form. I used the location X and Y to position the controls on the form. The loop work fine until it reach the point where the controls host panel needs to enable Auto Scrolling which cause the added panels to be shifted to right. The shifting happened once the host panel auto scroll becomes enabled.

rivate
Sub frmCapabilities_Load(ByVal sender
As System.Object, ByVal e

[code].....

View 1 Replies

VS 2008 .NET Child Form Controls Method Calls?

Sep 14, 2010

I have a MDI Form that has a child form containing a text box. I want to be able to make a call to the TextBox's cut() method on the currentlly active child form. Here's what I have so far, but it is complaining about using ctrl.cut()

[Code]...

View 3 Replies

Current Thread Must Be Set To Single Thread Apartment Sta Mode Before Ole Calls Can B

Apr 21, 2010

I'm getting the following error:"Current thread must be set to single thread apartment sta mode before ole calls can be made"

I am using Speech.Recognition.SpeechRecognizer and using it to open various dialog boxes. It works fine for the first few but on the third one when it calls the InitializeComponent in the Dialog's New, it throws the above error.

Anybody have any clue what causes this or how to fix it? The SpeechRecognizer seems to run on its own thread, so that seems to be at the root of the problem. If I open thedialog with a button click I don't get an error.

[Code]...

View 1 Replies

Thread State - Thread In An Application Which Calls A Sub Routine Main()

Jul 26, 2010

I have a thread in an application which calls a sub routine Main(). The Main sub routine in turn call several sub routines/functions from with the same module,several different classes in the same application. Also some sub routines/functions call routines from a class library. Now say the routine/function in class library goes into a infinite loop and never returns. I would like my thread in the application to raise a event and display message to the users about the infinite loop. I am giving some sample code for the application.

Imports System.Threading

Module VMain
Public gbSuspend As Boolean

[CODE]...

View 7 Replies

VS 2010 C++ Dll Is Not Thread Safe?

Apr 19, 2012

I'm calling a c++ dll I made myself - and it appears to be very VERY not thread safe!

I'm referencing it like this

<System.Runtime.InteropServices.DllImport("D:ACS DesktopdcxdcxDebugStringLibrary.dll", EntryPoint:="firstIndexOfKeyword", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl)> _
Public Shared Function firstIndexOfKeyword(ByVal s As String, ByVal substr As String(), ByVal substrLength As Integer, ByVal markers As Integer()) As Integer End Function

Is there a way to make this IMPORT create something more threadsafe?

[Code]...

View 10 Replies

VS 2010 Seems Like This Is Not Thread Safe

Feb 27, 2012

I'm dropping into this function - from several threads - to add an OBJECT to a dictionary collection

Private Delegate Function ReaderRegisterDelegate(ByRef rrFSOb As FSObject) As FSObject
Private Function ReaderRegister(ByRef rrFSOb As FSObject) As FSObject
Try[code].....

It's getting Object reference not set to an instance of an object.The FILEID key being added is F1. F2, F3 and F4 are in the dictionary. Seems like F1 arrived and the object wasn't properly setup. Or thread-slice caused me to see a partially messed with dictionary list?How can I make that a thread safe operation? I thought dropping out to the UI thread was a safe place to mess with code like this? Oddly enough I can go to the immediate window and do this

m_FSObCollection.Add("F" + rrFSOb.FileId.ToString, rrFSOb)
?m_FSObCollection.Count 4

ex.data is a dictionary list that looks like this

directcast(ex.Data , System.Collections.IDictionary).Count 0

View 6 Replies

.net - Is The Enqueue Method Thread Safe

Nov 2, 2009

Let's say that I have a module that has a Queue in it. For other entities to Enqueue, they must go through a function:

[Code]....

If I have multiple threads running and they want to call InsertIntoQueue(), is this considered thread safe? I am under the impression that there is only one copy of the instructions in memory necessary to perform the InsertIntoQueue() function... which would lead me to think that this is thread safe. However, I wonder what happens when two threads attempt to run the function at the same time? Is this thread safe, and if not, how can I make it thread safe? (and What would be the performance implications regarding speed and memory usage)

View 6 Replies

Thread-safe Text Box Update

Jul 26, 2011

I have a TCP server app that starts 2 threads when the server is activated, I want the threads to add text to the textbox on the main form. Here's is what I have tried [code]I have added MsgBoxes at points so I know the Sub updatetext_ is being called, and the text is being passed, they are also showing that InvokeRequired is always FALSE. In any case the textbox txtMessages is not being updated.

View 11 Replies

VS 2008 List (Of T) Is Thread Safe?

Sep 5, 2009

On the MSDN docs for the generic List(Of T) class, it says this:

Quote:

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.but I'm trying to work out what exactly that means or why it matters. Does that mean that if I had this:

vb.net
Public Shared MyList As New List(Of MyClass)

then I could enumerate through that list from several threads at once without there being a problem? I thought you could read from any object from multiple threads without a problem anyway... I thought it was only if there were potentially other threads modifying that object at the same time that there were problems. Particularly with a collection like a List because you cant modify a list while another thread is enumerating the items in the list as you get an exception thrown stating that the collection has changed. I think basically what I am asking is if the MSDN doc said that a public shared list wasnt thread safe then what difference would it make?

View 5 Replies

.net Thread Safe Method To Add A Listview Subitem?

Feb 21, 2011

I am trying to add a subitem to a listview in a threadsafe manner.In a single threaded application it works like so:

[Code]...

However if run in another thread it causes a cross threading error.I have looked at examples of delegate subs that use Invoke, but all examples i have seen involve updating the text property of an object, and i cant get my head round how to apply the concept to actually add a subitem to a listview.

View 3 Replies

C# :: FIFO / QUEUE With Buffer And Thread-safe?

Jun 19, 2011

I'm receiving tons of statistics data that I need to insert into the db.I would like to implement some kind of Queue or FIFO class that keeps all the dataand when it reaches to a specific count (buffer), it will send that data to the SQL through bulk insert. This should be thread-safe.

View 3 Replies

Safe While Using A Thread Pool With A Global Mysqlconnection?

Mar 1, 2011

Im creating a service for a mobile platform and I need to process user messages on a different thread than they were created on to leave the threadpool open.Anyway my App will be using a MySQL database and when it gets a message it will add the message to Another thread pool. But in the sub that procceses the messages I will need to perform query's on the database. So i know i can use a global variable and it will be visible to all threads but is making database operations safe while using a thread pool with a global mysqlconnection?

View 2 Replies

VS 2005 Thread Safe - Get All The Items From Listview

Sep 16, 2009

I currently have a form with a listview. On another form, I would like get all the items from that listview. This I can achieve but I always get the "Cross-Thread operation not allowed exception" message. I've tried the following code to avail.

[Code]...

View 9 Replies

VS 2008 Making A List Thread Safe?

Aug 26, 2009

I am using WCF to make a chat application - I dont think the fact I'm using WCF is relevant for this particular question but just thought I would mention it in case there is something special about the way WCF does threading that I dont know about.So I have my WCF service that runs on a server and a WPF app that acts as the WCF client - each time a new client signs in or out it updates the server WCF service to let it know that it has changed status. The server then updates a list to either add or remove the user, so this list basically represents who is online at any one time. The list is declared in the core server class like so:

vb.net
Private Shared List(Of ChatUser)

So, I have a method in my server side that is called whenever a user needs to be added to this list and originally I thought I could have some issues because while the server might be looping through this list to find out who is online, another user might have signed out and the list would therefore be modified while the server was looping through it which would cause an exception. So I added the following to the start of the method that removes a user from the list:

vb.net
SyncLock New Object

and I havent had any problems... but I'm still not totally convinced that this will completely solve the issue. So would creating a Property give me a bit of extra safety? Assuming I always used the property to access the list in my code.
Like this:

vb.net
Private Shared Property CurrentClientList() As List(Of ChatUser)
Get
SyncLock New Object

[code].....

Also, am I actually using SyncLock correctly? I mean should I be referring to a shared object that all of the threads can access rather than just doing New Object each time or does it not make a difference?

View 9 Replies

Asp.net - Accessing Httpcontext In Shared Function Thread Safe?

Jan 5, 2012

Im having a problem understanding if accessing httpcontext inside a shared function, without passing in the httpcontext as a parameter is thread safe?

Are the 2 functions in the util class equally thread safe?

Class foo
Sub main()
Dim qs1 = util.getQS(HttpContext.Current)

[Code]....

View 2 Replies

Parallel.For Listview Items In A Thread Safe Manner?

Feb 22, 2011

I have a small program that checks webpages for certain strings. I am using VB express 2010 .net version 4.I have the list of URLs in a listview, and loop through all the urls, perform a webrequest, check if the source contains certain strings and then add a subitem to the current listview with text to indicate the result I am attempting to speed the application up using a parallel.for loop, but this causes a cross threading exception.This is the code for single threaded:

For i As Integer = 0 to lvUrls.Items.Count - 1
Dim lv As ListViewItem = lvUrls.Items(i)
lv.UseItemStyleForSubItems = False

[code]....

View 2 Replies

Thread Safe Method Invoke Doesnt Work?

Jan 2, 2010

I Have a Function on my frmMain Class wich will update my control to something else after an invoke. When i type "?Label1.Text" on the Immediate Window, the text property IS updated, but when i go check the Form, nothing happened. The code is just like this

[Code]...

View 3 Replies

Thread Safe To Throw And Catch Shared Exceptions?

Jan 25, 2010

so i have a Method that is going to made Thread Safe. can i have something like this in the Method:

Public Class Q Private Shared ASD As New MyException("") Public Sub W Throw ASD if multiple threads attempt to throw the Shared exception ASD, will there be an error in the catching part? The alternative of course is to: Throw New ASD but i'm just checking to see if the first way is thread safe

View 4 Replies

C# - Does Queuing Threads Impact Non-thread Safe Objects In The Same Class

May 23, 2011

c# - Does queuing threads impact non-thread safe objects in the same class?

View 1 Replies

Does Queuing Threads Impact Non-thread Safe Objects In Same Class

May 7, 2009

If I spawn a thread with ThreadPool.QueueUserWorkItem and that thread does not reference the object that is not thread safe, would it compromise that non-thread safe object? By not thread safe object, I mean a third party interface to a programmable logic controller that has no ability to open simultaneous connections or concurrency support.I suppose I just wanted to be sure that by queuing threads in the same class as my reference to that object, I wouldn't somehow be compromising its thread safeness in a way I didn't realize.

View 2 Replies

Cross-thread Calls To Read (only) A Control's Property

Jan 14, 2011

On a given application form, I have around 20 controls that I need to set in the main form. I have a separate thread that only needs to ready some properties from the controls on the application form It will never try to write to the form's controls.

[Code]...

View 9 Replies

Form Controls Changes From The Windows 7 Format To Older Formats On Runtime While Running .net Windows Application

May 15, 2012

I have seen this happen before but am not sure how I resolved it in the past. On runtime the controls of my form change from the windows 7/vista format to an older version format as shown in the attached image.

How to display the controls in the format on the left (new windows format)

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved