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


ADVERTISEMENT

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

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

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

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

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

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

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

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 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

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

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

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

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

Update A Textbox With New Text From Another Class On Another Thread

Apr 16, 2011

im still stuck and i really to get past this and move onto the rest of my program. I'm trying to update a textbox with new text from another class on another thread. I can get this to work no problem on another thread with the same class, and on the same thread in another class. but not on another thread on another class. my code looks like this, when it is run to produces no errors but does not add the test to the text box, what is wierd is i had made some changes to the program to add multiplelines to consolebox.text and then checked console.text from form2 and it produces the values i added but those arent reflected inside in the consolebox for some reason.

[Code]...

View 1 Replies

Using Thread To Update Label Text On Form

Jun 8, 2010

I run a thread from my main form that do some stuff i want that each action that the thread do will be written on a lable on the main form. How can i do that? I try to give it a pointer of the form but with no luck since its not allowed by the compiler. here is how i create the thread object in my form:

[Code]...

View 2 Replies

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

Update The Button Text On A Form From A Backgroundworker.do_work Event, And It Failed With The Usual Cross-thread Exception Message?

Nov 14, 2011

I tried to update the button text on a form from a backgroundworker.do_work event, and it failed, with the usual cross-thread exception message.However, by pure chance, I also tried to update text in a system.windows.form.toolstripstatuslabel also from this backgroundworker.do_work event, and it DOES work. Question: why is this? Is it perhaps because theres some kind of implicit shared behaviour with system.windows.form.toolstripstatuslabel?

View 4 Replies

Update ProgressBar From Another Thread (Thread Is Not A BackgroundWorkerThread)

Nov 18, 2009

I have a program that runs for some time and I would like to update the user on its progress. The rest of the GUI is updated using Delegates and Invokes and such (Java is Soooo much cleaner in this regard - everything is thread safe!!), but there is no invoke method for the progress bar. How can I use a delegate to update the progress bar when there is no invoke to invoke!!

View 1 Replies

Is Array.Contains Thread Safe On A Readonly Array

Aug 31, 2011

Is Array.Contains thread safe in the following context.A static array is declared and initialized with 4 elements in a function.Static validRotations() As Integer = {0, 90, 180, 270}It is then only accessed using validRotations.Contains(rotation) in the same function.

View 2 Replies

Write In Worker Thread In A Data Table And Rich Text Box in Main Thread

Mar 4, 2009

I'm creating a Client Server application which involves theServer running some scripts in clients and getting back results in an automated way. In Server, other than Main thread, i have 2 worker threads, a) one monitoring response from clients and b) the other scheduling next available job to respective client which executes that job. The issue here is ,I want these worker threads to write the status of their work in the UI(which comes under Main Thread). Also i need to write things in worker thread in a Data table and Rich Text Box in Main thread. But, I can't do so, since it has been blocked to access one thread's function or property directly from others. Is there any work around to do this?

View 8 Replies

Update UI From Different Thread?

Jun 15, 2010

Im working on a program ( vb 2005 CE framework ). I have mainly two threads, the main one and another one I use it for a different thing.When I tried to update the UI this exception was thrown : Control.Invoke must be used to interact with controls created on a separate thread.well !I have tried to use the INVOKE, but it wouldn't work. this is where I get the error :

Public Sub PaintKeys()
Dim tempLevel As clsLevel
Dim tempKey As ClsKey

[code]....

View 5 Replies







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