Sync Locks - Manage Access To A Collection Object From Multiple Threads - Add, Update, Remove, Clear
Oct 20, 2009
I am considering a piece of code that will manage access to a collection object from multiple threads - add, update, remove, clear. OK ... so I have put a sync lock within each method, but what is not clear from the MS documentation is exactly how the sync lock is behaving. Is it locking the piece of code it wraps? Or is it locking the object? And if it is locking the object a private static object should lock out any code locked on the object within all instances of the object? i.e. if an add operation is underway, an update, delete or clear will wait for the lock to be released.
Finally, if I have multiple threads contending for the sync lock, how is the release managed? First come, first serve? random (from my p.o.v)? Is there a chance that two separate threads could blunder into 'locked' code simulataneously?
View 2 Replies
ADVERTISEMENT
Apr 30, 2009
I am trying to have multiple threads run through an arraylist of object and process each object. My problem is that each thread processes every object in the array.So they are not working together on the job. I made sample application to show my problem. I think the problem is somewhere in my ThreadSub() Here is the
Imports System.Threading
Public Class Form1
Dim myitems As New ArrayList
[code]....
View 2 Replies
May 31, 2012
I have this class and I have a loop that launches multiple threads from the same class. This is all done from the main form.Now I want to update the richtextbox on the main from these classes.I have tried those begininvokes etc etc and nothing worked, no error but no output as well.Here the code for launching the threads :
Private PingObjects(100000) As Account 'Account is the class and login is the sub in it...
PingObjects(I) = New Account
Threads(I) = New Threading.Thread(AddressOf PingObjects(I).login)
[code]....
And to update the rtb, im using MainForm.log.text = "....." Nothing happens, no error.I have tried using the begin invoker method as well.
View 2 Replies
May 27, 2012
Been a while since I did any VB work, and have started a new project that is a Windows Service that will update a database using multiple threads. I am testing this out with a dataset that consists of a "device name" and a "device IP", pinging the device, and attempting to update the device's "status".
I have it working in a single-thread type configuration, but would like to be able to ping and update different records across multiple threads (for obvious reasons).
The problem I'm having is with the logic mainly. When the service is started, I get all the devices from the database and fill a DataSet. From there, I am looping through the dataset's rows, pinging each device and updating the record. I know how to spawn multiple threads, but I do not know how to keep track of updating the correct record and also making sure that all records are checked in some kind of order. Like, if user specifies 5 threads, I need it to get record 1, thread finishes, gets record 6 (while other threads execute), or something like that.
Note: this does no interface updating or anything like that. Only updates a database record's field value.
View 37 Replies
Aug 4, 2010
I have an application that needs to perform a series of different actions at specific points in time.To do this I have a timer with various actions that occur in its tick event.One possible action is to send out a few messages via a serial port and then wait (between 1- 300 mins typically) for the next timer tick.Another possible action is to continuously toggle one of the control lines on the serial port until the next tick (again 1-300 mins).
In most instances, i'm happy for everything to run on the main thread, but in the case of toggling the line endlessly, I thought it better to give it its own thread.My problem is that for the new thread to use the Serial Port, it must open the port. Likewise, it must close it before the main thread can have it back.
Here are 2 code snippets
Private Sub activityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles activityTimer.Tick
Dim some variables here
activityTimer.Stop()
If speedThread.ThreadState = ThreadState.Running Then
[code]....
View 4 Replies
Dec 23, 2010
I have a datagridview with two columns a text box and a combo box. I can add to the combo box collection but can't determine how to remove part of a collection. Example combobox has 10 items as follows: 1,2,3,4,5,6,7,8,9,10.
I only want to show a number 1-10 when another label has the same associated number.I have 10 labels named 1-10 but I only want the combobox to display a number 1-10 when the corresponding label has been selected previously. So, if labels 1-5 have been selected by the user than I want to have my dgv combobox to display only 1-5 and remove 6-10. I have searched but have not been able to find a similar post.
View 9 Replies
Mar 18, 2011
I recently had some problems with the performance of the Word object model. In an add-in that I wrote for Word I need to parse through all the words of a document and replace some of them or ask the user for the ones that have multiple replacements. I know that it is faster to ask Word for all of the document text content at once and then process it and put it back all at once again, but this is not suitable for my add-in because I need to have access to the range objects that represent the words that have multiple replacements so that I can somehow mark them in the document and present the user with a tool tip from which he can select the replacement he wants.
So for the moment the single great speed improvement that came in my head was multithreading since most people already have dual core or better. The problem is that all the things you find on Google say that multithreading in Office is a very bad thing to do.
So is there any one who managed to do this in a manner that worked in most of its usage? By this I mean if it also worked on other PCs then the development one?
View 1 Replies
Jun 5, 2010
I have a function which does some processing. Lets name that function DoWork. This function takes some inputs as structure and a string. Now I want to start two threads which would read some elements in an array and then call DoWork with some data and value of that element. DoWork would do processing and thats it. I want two threads to run side by sid.
So I tried to write code but kinda failed. I wrote a function which starts a thread and calls DoWork. Now DoWork accepts structure and string etc. But when we do say abcthread = new threadig.thread(addressof <sub name>). here we cant pass any-value except object. That was first problem.
Anyway, main problem is after the thread has finished processing DoWork, how do I find that out and tell that thread to take another element from array and start again. This has to be managed for both the threads. I need to find out which thread has finished first and tell it to start again with another value. I have usually used one thread but not two in this way.
View 15 Replies
Apr 14, 2010
I am using Synclock to prevent multiple threads from logging text messages to the same file at the same time, but this doesn't seem to work:I get frequent sharing errors on the logfile, within the synclock block.The Synclock is using the variable holding the filename, because it exists all the time and because it is always the same object, whatever class instance or thread I'm in.[code]Despite using Synclock and a Using block around the code, I keep getting this error in the sw.WriteLine(Msg) line:System.IO.IOException: The process cannot access the file '(filename)' because it is being used by another process.Should I use some other type of object than a string to synchronize on?I cannot use a user interface object (button or so) because it is a windows service project.It was written and compiled in Visual Studio 2008, but targeting the 2.0 framework because it has to be able to run on some old Win2000 machines.
View 12 Replies
Oct 19, 2011
I just had a new, last-minute idea on to take on a task, so I am running to StackExchange for quick help.
What I want to do is execute a series of methods right in a row, each in their own threads. I want the application to wait until all of these threads are completed, after which the program will resume. It also has to use managed threading (thread pool).
What quick examples could you provide to help me along the way? If it's too complex, what things should I know about so that I can Google it on my own?
View 1 Replies
Jun 6, 2011
I trying to make a code to Delete and Update Access 2007 database after remove a selected item from a listbox in VB 2008. [using "Remove" button that i create] pervious i already make a button to View data from database and Remove from listbox. but i don't know how to delete and update in database.
The code i using now:
CODE:
In the database, i have ID,Name and Age (simple database)
View 1 Replies
Apr 13, 2011
I am trying to run a backgroundworker to load data from my DAL (which is available in another class). I want to keep the UI available and not have the "locked up" feel while the object is loading.When I create a simple backgroundworker and Sleep the UI stays responsive and my controls can be updated after the sleep. As soon as I replace the sleep with a call to instantiate the object from my DAL, the UI locks up. Is there someway I can instantiate this object using the background worked and keep the UI responsive?
When the situation object is instantiated it could take several seconds for it to load completely, during this time is when the UI is locked up... It does eventually load just fine.
Private WithEvents backWork As New BackgroundWorker()
Dim sit As Situation
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLoad.Click
[code]....
View 1 Replies
Dec 19, 2011
I am developing an desktop application using vb.net. I have an doubt, can update or sync database which are at different place. Means changes done at one place should get updated in other.
View 12 Replies
Feb 27, 2012
I'm just wondering how to sync multiple WebRequests in function? I'm using this now, but sometimes the requests dont go through...
For i = 1 to 10
Dim request As Net.HttpWebRequest = Net.WebRequest.Create("http://www.site.com/test.php?w=" & "TEST")
request.Method = "POST"
[code]....
View 1 Replies
Mar 24, 2009
I'm an experienced Office & VBA programmer, I am new to .NET programming. I'm in the process of migrating an Access 2007 database application from Access to Visual Studio Visual Basic project for further development. In particular, I am interested in using .NET controls to display data in a user-friendly hierarchical grid control.The data for each hierarchical display is stored in two separate tables (I call them tblData and tblExtraInfo), and then I use a query to join the data and prepare for display (I call the query qryBOM).
[Code]...
View 1 Replies
May 30, 2009
I am trying to select Multiple files and then read the file 1 by 1, i want to know how to specify the file number in Visual Basic .net 2008
Here is a sample code which i have used in reading the text file.
With dlgOpen
.Filter = "txt Files (*.txt)|*.txt"
.Title = "Open Text Files"
[Code]....
Actually my text file is a dump file and i need to make a program to process this dump file. I may ask some stupid questions but this is just a beginning, i want to parse INDIVIDUAL text file line by line. In the above code i have used the ReadToEnd function in order to display it in TextBox but i may use ReadLine Function or Read function to read line by line or characters respectively.
I have attached an Access Database with the predefined tables in it, I want to update the contents in Access Database. Supposingly if my textfile contains Names (Sam,Julie,Joseph,Marina), how will i update my attached Access table in vertical order !
View 1 Replies
Nov 30, 2009
I need to clear a dictionarybase collection have tried the below mentioned method but it gives me an error... any help please?? ( in the Public sub MClear....) here's the code:
Imports System.IO
Public Class IPAddresses
Inherits DictionaryBase
[code]....
View 1 Replies
May 26, 2010
If you are working on a large record in database. How you manage to use the INSERT,,UPDATE? I mean when selecting a record base on two tables or more and those tables consist of 20 columns it hazard to put all those columns in one query.
[code]...
How to lessen the code without typing all those queries over and over again ?
View 3 Replies
Jan 25, 2011
I have the following problem, a table "table1" contains 10000 telephone numbers, this table is source for 5 combo box contained in a form, I need that when I select the first tel N in the first combo, this number is not any more available for the combo 2, when I select the second number in the second combo, the first 2 numbers of the table 1 are not any more available for the combo 3 etc. Every record (in form) contains 5 combo. The Tel N selected into the combo are source for other table called "table2". I've try with all the type of query between table 1 and table 2, and use the result as source for the combo, I've try with IIf but this is works only for the first combo.
View 3 Replies
Nov 8, 2011
How can I create a GUI in vb.net similar to the one above?i.e.there are "buttons" on the left which changes the main window when they are clicked.One way I thought of is create many panels overlapping and show/hide them when a certain button on the left is clicked.
View 2 Replies
Sep 15, 2011
I have a loop that creates several threads as such[code]...
View 1 Replies
Feb 23, 2011
How to manage multiple tables with the same structure. However, due to the craptastical nature of VB, the solution doesn't really work. It specifically doesn't work because VB.NET requires the implementation of each method/property in the interface to be explicitly declared.
As for the problem that I'm really trying to solve, here it is:
I have many lookup/domain tables in the database that all have the same structure.
The items in these tables are typically used for drop downs in the interface.
I would like to avoid a bunch of boilerplate repository methods to retrieve the contents of these tables (one method per table really sucks when you have 40 tables).
I am not using the One True Lookup Table anti-pattern and this is not an option.
View 2 Replies
Aug 1, 2009
What would be the best way to manage multiple Picture Boxes?I am thinking an array, but if that is so, how would I build this array, and what would be stored in it?
View 1 Replies
Feb 13, 2010
How best to manage multiple dat files for serializable objects of the same class. If one of my data files goes past a particular size, I want to create a new file. I then loop through both files when I do processing. Is there any easier way to do this and what's the best size to do this at in terms of performance?
View 1 Replies
Mar 25, 2011
I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution. These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:
[Code]...
View 3 Replies
Sep 28, 2009
I have an issue with a data base updating it won't update for me in debgging mode it is stopping here on this bit of code which is highlighted in red. the error which comes up is .(update requires a valid update command when passed datarow collection with modified rows.)
Public Sub UpdateDataSource(ByVal ChangedRows As database.dataset1)
Try
'The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
[CODE]...
View 1 Replies
Apr 9, 2010
i have a series of CSV files that are posted to a specific web folder that I can specify in network places. Each file has same structure, lots of fields, and have consistent name schema "prefix-mm-dd-yyyy.csv". i need to use VB to process all these files, either individually or by consolidating into one file and appending to an existing table. i also need to somehow add a "download date" field to the process so i can show when the file(s) were appended. then i need to verify that it worked ok so i can then, still within VB, move the files out of the folder, such only the CSV files that have yet to be imported/appended are in the folder (so I don't have to guess about which files I have already uploaded and processed.i can figure out how to make a DO UNTIL loop, but i can't get the import statement right... nor can i figure out how to verify that the import happened in order to move (or remove) the source files.
View 1 Replies
Jan 13, 2010
Here's the link I'm currently using for reference: mages for error list:
Public Class FrontPage
Dim cnn As New OleDb.OleDbConnection
Private Sub btnclose_
[code].....
View 8 Replies
Oct 2, 2011
Some controls are dynamically created within a panel. Their event handlers are attached
Dim btn as new system.windows.forms.button
with btn
'set properties
[Code]....
View 4 Replies
Sep 23, 2009
My VB project is large enough that it requires several files. It was originally developed as a Console App and I created each file as a MODULE. All modules could use subroutines, data structures and constants from other MODULES and everything worked fine. I needed to add basic windowing to the app and this required that the app be converted from a Console App to a Windows Forms App. The main window is Form1 which is not a MODULE but a CLASS. The problem is that some MODULE based functions cannot access subroutines, data and constants that are defined within the CLASS Form1 unless they are incorporated into the CLASS file and this makes the CLASS file very large. If I add a new Class file to the project, it also cannot interoperate with Class Form1 in the same way that multi-MODULE code interoperates.
How does one spread CLASS code across several files and still allow it to interoperate as if it were in a single file? Alternatively, how does one create several CLASS files that operate the way multiple MODULE files operate.I am sure that there are all kinds of best practices that I am violating but the goal to to get some prototype software working and interfaced to some lab equipment.
View 2 Replies