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


ADVERTISEMENT

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

VS 2010 : Copy This Array To A Temp Array So That The Temp Array Has All The Same Values As The Original Custom Array?

Jun 19, 2011

I have an array of people stored in a custom structure array... how can i copy this array to a temp array so that the temp array has all the same values as the original custom array?

View 4 Replies

Seaching An Array - Store In A 1d Array A Set Of 5 Place Names And In 2d Array The Distances Between Places

Jul 28, 2010

I am trying to create the following program Store in a 1d array a set of 5 place names and in a 2d array the distances between the places. Ensure that the order of the places is the same in both arrays. When the names are places are input the distance between them is displayed. If they are not both in the table a suitable message is displayed

Dim town(1 To 5) As String

Dim Dist(1 To 5, 1 To 5) As Integer

Dim First As Integer

[CODE]......................

I think the best way forward is pass a parameter to the function findnumber.

View 1 Replies

File I/O And Registry :: Safe A String Or Byte-array To File In Utf8 Format?

Sep 4, 2008

trying to find a decent answer for my question; I do have a utf8 file which I (down)load, manipulate and wanting to save back again.The result always is that the file I produce is not in utf8 format;

Dim fs2 As New FileStream("c: est.dat", FileMode.Create, FileAccess.Write, FileShare.None)
Dim w As New BinaryWriter(fs2, Encoding.UTF8)

[code].....

View 3 Replies

Buffer/Array - Safe Application That Contains 3 Threads - Data Acquisition And Decoding - Data Graphing - FFT And Filtering

Aug 26, 2009

I am trying to write a thread safe application that contains 3 threads : -

1 - Data acquisition and decoding
2- Data graphing
3 - FFT and filtering

Thread 1 is collecting bytes from the serial port and converting them int integers (so taking two bytes) after is has captured 64 Bytes and converted into 32 integers, it then needs to pass the array to the graphing thread.

The graphing thread then plots the data and waits for more data.

Thread 3 also waits until thread one has collected 2023 integers and takes these and performs some FFT calculations (which take time).

My question is how do i share the arrays between the three threads without deadlocking the program? as the serial thread will be flying around reasonable fast (1000 bytes per second) so it will synclock onto the shared buffers for most of the time.

Originally i was going to use two synchronised queues, so when thread 1 has collected 32 bytes it queues the data into the graph queue, and once it has collected 2023 it queues the data into the FFT queue.

Then thread 2 and 3 can simple dequeue the data.

However using queues has the overhead of casting the data in and out, and as i know the data type i was planning on using two arrays :-

Dim GraphArray() as ushort
Dim FFTArray() as ushort

Then Thread 1 adds data to each thread, and thread 2 and 3 simple wait until the correct amount of data is available before removing the data. my question is there an array type that allows me to remove x amount of data from an array?

Because i cannot do this easily with the ararys defined as above (GraphArray, FFTArray), as i was planning on making them 1mByte and allowing thread 1 to fill them Knowing they should never overflow and then let thread 2 and 3 remove x amout of bytes at a time unless there is a better way of doing it

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

VS 2008 Pass Array To Thread

Nov 4, 2009

Further to:- [URL] I now need to pass an array thus:- HTML

[Code]....

Myarray can be redimentioned. Since I need to pass an OBJECT to the thread how do I get the thread to recognise the passed array?

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

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

Cross-thread Operation Not Valid In Label Array?

Jun 20, 2011

I have a problem: When try to change the text of a label array (label(1).text = "Lol") then I get a error:

"Cross-thread operation not valid: Control 'lblCSCH1' accessed from a thread other than the thread it was created on."

The code is this:

Private Sub Cliente_Receive(ByRef message As String) Handles Cliente.Receive
Dim anterior As String
Dim corte As Integer

[Code]....

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

Syntax For Control.Inoke To Send Integer Array From Backgroundthread To UI Thread?

Jun 24, 2010

with the code below, I'm trying to send an integer array from a background thread to the Main Form which contains a User Draw Control. I currently get the error:"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Public Class Form1 Me.TabPage.Controls.Add(Me.DrawGraph) 'designer.vb
Public InjectIntegerArrayDelegate As InjectIntegerArray
Delegate Sub InjectIntegerArray(intarray As Integer())
InjectIntegerArrayDelegate = New InjectIntegerArray(AddressOf InjectIntegerArrayMethod)
public Sub InjectIntegerArrayMethod(SensorData As Integer())
DrawGraph.Int_Clutter_In = SensorData

[Code]...

View 4 Replies







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