Multi-threading With SyncLock And Invoke?

Mar 5, 2009

Once again Invoke has come back to haunt me! I have an application that has some background threads, serial communications and obviously a GUI. Now, the serial ports received incoming messages as events and these get processed and incoming data is logged both to a file and also appended to a RTB in the GUI (done using Invoke if InvokeRequired is true).Now, under normal circumstances everything is super happy and runs quite nicely but when stressed I reach some sort of deadlock.

What happens is I have two methods AddOutput and RemoveOutput. These both sync over an object SyncOutput As Object. When messages are received on the serial port they are processed and depending on whether or not a response is required AddOutput is called. This adds out going messages to a dictionary which is then accessed by a thread and the messages are sent out. If an acknowledgement message is received then the corresponding message in the dictionary is removed.

[Code]...

View 2 Replies


ADVERTISEMENT

Multi-threading Scoping - Enclosing The Test Module Portion That Hosts The Delay In A Synclock Results?

Jul 16, 2010

I'm on my way to MSDN but thought I'd stop by here first because the answers are usually more cogent.I have a test bed that mimmicks my product app. The general architecture is a factory that builds/instantiates a number of objects (device controllers) that are scalable in number based on requirement. Each object has a threaded portion that reads a device. This way, each object can read its own device simultaneously with all the others. To perform the read, the object calls a routine in a Module that houses the device interfaces. Interestingly (and happily), it seems like each thread has its own copy of the Module routine.

The test bed seems to verify what I'm seeing in the app. In the testbed, a 500 mil second delay is substituted for the device call. Even enclosing the test module portion that hosts the delay in a Synclock results in multi-threaded execution of the pseudo device call. I haven't tested for data yet, but this seems to indicate that when the module routine is called from controller object, it too carries it's own copy of the data just like the calling object. As a long time c++ programmer...that don't quite seem right.

View 2 Replies

Invoke Within SyncLock Causes Deadlock

Apr 13, 2011

I was wondering if this is known / expected behavior. By design?Is it documented somewhere?

My 'real' code does need something to keep one thread from accessing a listview while another is busy clearing and refreshing the Items collection, so it's not as easy as omitting the synclock section in the example below (The SyncLock in my case is on the ListView).

This code, which can be pasted over a new empty form's user code class, deadlocks during the Invoke call. It doesn't reach the entry point of SetText (setting a brakpoint there, the deadlock occurs before the breakpoint is hit).[cod]e...

View 4 Replies

VS 2008 Multi-threding - Adding Multi-threading Facilities - Cross-thread Operation Not Valid

Feb 10, 2010

I'm adding multi-threading facilities for the first time. I have a function that is wrapped to be run in a separated thread. This function retrieves data (text) from a combobox and it works for sure without multi-threading.

When I call it as multi-threaded, I get the following error when I try to retrieve the data from the cmobobox: Cross-thread operation not valid: Control 'cmb1stBL' accessed from a thread other than the thread it was created on.

It looks like a restriction of thread-safety... I assume that the child thread cannot read from his parent, to make sure that he doesn't change his parent data. So how can I read the data from the combobox? Should I read the comoboxbox data before calling the child thread?

View 4 Replies

Accessing Multiple Sites Multi-threading Or Multi Browsers?

May 14, 2011

I have a need to build an app that will access about 10 websites and pass data to them, etc.I've read about something called multi-threading when searching Google. I've also seen people say that they use multiple browsers.Which route is better to use? I figure if you have to do some sort of multi-threading that you would access a single browser?

View 2 Replies

Cross-threading Operation Not Valid Even Though Invoke Is Used?

Sep 28, 2010

I've been reading around trying to find out why I'd be getting this exception to no avail.

I'm using Visual Basic 2010.

Briefly, I have a "Settings Panel" form which takes a while to create (it contains a lot of labels and textboxes), so I create it in another thread.

After it's loaded, it can be viewed by clicking a button which changes the form's visibility to True. I use the following subroutine to handle invokes for my controls:

Public Sub InvokeControl(Of T As Control)(ByVal Control As T, ByVal Action As Action(Of T))
If Control.InvokeRequired Then

[Code]....

The SettingsTable.Create() method generates a bunch of Labels and TextBoxes based on the contents of the application settings and adds them to the SettingsTable.

When I click on the ViewSettingsPanel checkbox, I get a cross-thread violation error.

View 1 Replies

Multi-threading Or Multi Browsers?

May 14, 2011

I have a need to build an app that will access about 10 websites and pass data to them, etc.I've read about something called multi-threading when searching Google. I've also seen people say that they use multiple browsers.Which route is better to use? I figure if you have to do some sort of multi-threading that you would access a single browser?Not sure which way I should approach this app.

View 2 Replies

.net - Which Cross Threading Invoke Function Is Better For A Control That Is Inherited

Nov 9, 2009

I have a relatively simple question regarding the best way to call the DataGridView.Rows.Add function when it is inherited into the current control. Which is the best way to make the call to the inherited control? Call it directly in the invoke or call it using recursive-like function? They both seem to produce the same result, a row gets added and the quantity is returned, but which is the most efficient?The delegate: Private Delegate Function ReturnDelegate() As Object

The two ways are:

A)
Private Overloads Function AddRow() As Integer
If InvokeRequired Then
Return CInt(Invoke(New ReturnDelegate(AddressOf AddRow)))

[code]....

View 1 Replies

Exception W/ Threading And Invoke In A Class - Read A Sock Without Freezing The Thread?

Mar 12, 2011

I have created a class for Socket reads so I can create sockets on command. Due to performing a socket read, the program will freeze waiting for incoming data due to being on a single thread. So I created a separate thread for the reading of the sock and attempt to invoke an event to prevent multi-threading errors.

But I am getting an error when trying to Invoke: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

How can I fix this or is there a better way to read a sock without freezing the thread?

Class for Sockets:

Option Explicit On
Option Strict On

Imports System.Text

[CODE]...

Calling form code example:

Private WithEvents Socks As clsSock

Private Sub Sock_Connected(ByVal state As String) Handles Socks.Connected
MsgBox("Connected - " & state)

[CODE]...

View 4 Replies

Best Way Of Multi-threading?

Mar 3, 2009

I need to be able to call a C++ dll that takes a long time (possibly infinte, it relies on user input)to execute. Im calling this through VB. My VB GUI freezes up when this happens, and I would like to keep the GUI responsive, so that the user can stop this possibly infinte loop. A bit of background, the C++ is trying to keep score on a snooker table using a webcam, and while the VB scoreboard updates easily, I would like to script it so that the analysis is almost continuous, while still allowing the user to interact. Currently the project requires the user to press a button to start the shot analysis, but it would be preferable if the program scripted itself. I have only realised this problem now and the deadline is very soon.

Update: Our lecturer suggested an option to solve the problem, but it would appear that most options here and the one he suggested will not work for us as the processing time required for the webcam image capture is too great to handle due to hardware constraints.

View 5 Replies

SMS Multi Threading

Jun 26, 2009

SMS Multi Threading

View 4 Replies

.NET Perform Any Multi-threading On Its Own?

May 30, 2009

I know .Net and C# pretty well, but never even looked at VB.My problem is: our Win32 COM library is used by a number of clients, and we see that the number of failures is higher for those who use the library from VB (both VB and VB.NET) than for those who use C++, C# or Delphi. One thing about our library is that it is supposed to be used from one thread only - can some threading magic by VB be the cause of failures?

Clients tell us the do not create any extra threads on their own.

View 3 Replies

Better Performance With Multi Threading?

Feb 15, 2009

I'm creating a password hash recovery tool that uses brute force. I have the brute force algorithm run in a background worker. It all works, but some similar apps I tried out have performance ~100x bigger then my app. (mine does 50k keys/second, some others do 5m keys/second or more.)I realize this is partly caused by using a .Net language, but I suspect there are ways to significantly speed up the brute force. A lot of ppl say I should use multi threading, but how is this done in practice? Splitting up the passwords to check would slow down my app I think.

View 1 Replies

C# - .NET Multi Threading - Updating The UI On The Fly

Nov 12, 2010

I have a button click event and inside I do a lot of work. While I am doing this work (not from the UI project) I want to send messages to the UI to display to the user.

[Code]...

and inside DoMyWork which is in another assembly i can call SendMessage which writes to the textbox. The messages will only display though when DoMyWork is complete. How can I update TextBox1.Text on the fly without putting DoMyWork on a BackGround thread or do i have to put it on a BackGround thread? I do actually want to block the user from doing anything while DoMyWork is running

View 9 Replies

C# - Multi Threading A Web Application?

Sep 9, 2009

I know there are many cases when it's best to multi thread an application but when is it best to multi thread a .net web Application?

View 5 Replies

Multi-threading In GUI Environment

Jun 22, 2010

I made a simple Form1, with Text.Box1 (starting value=1) and Text.Box2 (starting value = 100000), as shown in the attachment: I wanted that, when the Form loads,value of Text.Box1 keeps on increasing by 2 and value of Text.Box2 keeps on

[Code]...

View 1 Replies

Multi-Threading On Multiple CPU

Aug 20, 2009

One of our products consists of two different services:

- main service that launched at the startup of Wndows
- GUI that launched manualy when needed

GUI is representing data from main service.Main service starts X amount of threads that do some work and gether data.Some minor data and adresses to threads are stored in chache memory, so that GUI will have access to them.Everything works fine in 99% cases, but in some rare cases GUI do not display any data when used on machines with multiple processors (not milti-core). My guess is that it can't access the memory -> probably OS "decided" to run main service on one processor and GUI on another one.Is there any way to access the memory alocated for one processor from the service that runs on another processor?Or is there simple and secure way (same application will be also runing on single processor machines) to specify both services to run on the same processor?

View 4 Replies

Synchronization In Multi Threading In .net?

Sep 10, 2010

I have a question regarding the synchronization in multi threading.

I have a function called send which i am calling in a for loop for every data row.

This function creates threads to send emails to different people.

Public Sub send(ByVal Conn As Data.DataRow, ByVal job As Data.DataRow)
MyThread = New Thread(AddressOf Me.start)
MyThread.Start()
End Sub

But every thread created is writing to a log file at different points of time. So, there are very high chances that 2 threads write to the same file at the same time. So, do i need to use any kind of synchronization mechanisms here ? or is it fine without them ?

View 3 Replies

VS 2010 Having The Multi-Threading IP's?

Dec 11, 2010

I've been raking my brain for quite some time on this. Is there any way with VB.NET that I can use multiple IP's in one instance of a program? For example, I want to be able to navigate to a web page 10 times at once, with each one using a different IP. I want them to be parallel (multi-threaded) rather than going sequentially. Going sequentially, I could just do the action, change the IP, do the action, change the IP.

View 5 Replies

VS 2010 Multi Threading The Right Way?

Jan 10, 2012

I have a button and when it's clicked a HTTP request is sent out to a website to do a few things, but because its got to load the external resources it makes the interface frozen. I've moved the HTTP onto another thread using the follow

VB.NET Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Thread1 As New System.Threading.Thread(AddressOf check_accounts)

[Code]...

When i want to update a label that is on my main form (from the check_accounts sub). I know that isn't the right way, but i have no idea what the right way is. All the documentation i can find is very (excuse me for this) nerdy and really doesn't offer much insight on how to incorporate it into a project.

I want to be able to have a numericupdown box that can let the user change the amount of threads they want to use. I assume more threads allow the http requests to be done faster and at the same time?Also if i wanted to pause the HTTP requests, would the best method to use be pausing the thread?

View 12 Replies

Adding Multi-threading To Application?

Jun 15, 2009

I am working on adding multi-threading to my application. I have done two applications using multi-threading following a tutorial of sorts, and modifying the code to "get my feet wet."

This is the first time I am trying multi-threading within my own application, and I feel I should be beyond this type of problem, but after a 3 hour search on the forums, I can not find a solution, so I am posting this thread.

The section of code with the error

vb.net
Imports System.Threading
Imports SldWorks
Imports SwConst

[Code]......

View 9 Replies

Class Updates And Multi-threading?

Aug 29, 2010

using multi-threading in my application.Basically what i am trying to do from within a form event is initiate a class instance and then run a function of that class (via a thread) that changes certain member values of that class.Those class member values are then used to update values on the main form.Ive created a simple example below but i cant seem to get it to work.The class values are not updating and im struggling to understand how this threading works.

Class FormMain
Private Sub BtnClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myformbtn.Click()
Dim myFileCounter As New FileCounter()

[code]....

View 10 Replies

Difference Between Multi-threading Vs. Backgroundworker?

Apr 12, 2011

I'm creating an app that needs to navigate to multiple websites, logs me in and then submits my documentation.I've read that multi-threading can handle this task but then I've read something about backgroundworker.

View 1 Replies

Download File Using Multi-threading?

Dec 18, 2010

Download file using Multithreading

View 1 Replies

Multi Threading With Comm Object

Jun 20, 2012

We working with a Modem type interface that use's the Comm port for two way communication. The App starts and sets up the Comm port, and sends config info to the 'Modem'. Trick here is you have specific timing issues that need to be considered, and we got it all sorted, by using Threading.

You send The Config command to the modem and wait X ms for the confirmation reply (Single Byte), If no reply, send a Wake up command, wait X ms and send Config command again. Once confirmed that the modem is in config mode, send parameters, Waiting for confirmation of each one. Once config is set, send the 'Return to normal mode' command and wait for confirmation. [Code]

The SwitchModemMode sub runs under the Comms thread and not the main thread, like the Checkmodem sub at the top. Mostly because the Comms thread Raises the Data Event, which in turn calls the SwitchModemMode. Now because of that the Thread that is supposed to be checking for the input and setting the Flag, is actually the one waiting for the Flag to be set. And Yes App.DoEvents could solve it here, however that can/will mess with the Timing needed with these commands. I'm looking for how to pass the Raised event to the Main thread.

View 1 Replies

Multi-threading Bad File Name Or Number

Apr 18, 2012

I'm using VB2008 express under Windows XP.I have a complex program that processes digital maps. To speed things up I have started to use multiple threads.The program logs diagnostic information as it runs - a file is opened when the program starts, records are written (Printline) to it as required and it is closed when the program ends. All this worked fine until I introduced multiple threads.For the main program it still works fine - but if I try to print to the log file from the code in a started thread there is an IO exception "Bad file name or number". The number (1) is shown by the debugger and is correct.Does this mean that a file cannot be accessed by different threads without being opened and closed for each thread?

View 1 Replies

Multi-threading, Safe Variable?

Oct 1, 2011

I have apps with multiple threads. I never have two threads that write to the same variable, but I do have situations where one thread writes to a variable and another reads from it.Is this safe, thread wise? (talking from an execution standpoint) The practice, seems to work fine, but I don't know what would happen if in the split second if one core was reading the variable, and the other was trying to write to it. Do I need to set up some form of lock out here?

View 4 Replies

Use Multi-threading Or Delegates In A Service ?

Nov 6, 2008

Whether i should use multi-threading or delegates in a service that i am writing. I have written a couple of services before (with multi-threading) but think that i could have done a better job of it. The service does not have a UI, it only needs to interact with a database and around 800 ip addresses. I just need advice on which way would be better in terms of efficiency, if for example i needed to send data to all 800 ip addresses at once.

View 2 Replies

VS 2008 Multi Threading Query?

Apr 22, 2009

after i get a successful ping response i need to send an HTTP request to the device examine the response and then display it. i'm trying to multi thread the 2nd bit with no joy so far.

Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Threading

[code].....

View 2 Replies

VS 2008 Multi-Threading With More Than Two Threads?

Jun 5, 2009

I would like some advice on multi-threading. I currently utilize two threads, one for the GUI, and the other for calculations. This works well, but I want to improve my multi-threading techniques. Currently the data is with the calculation thread, and this occasionally this will cause a slow down. I want to put the data on its own thread. Giving me three threads, Data, UI, and Calculations. This should improve responsiveness, and not be overwhelmingly complex.

My problem is, this no longer fits into the parent child relationship well. All three threads need to interact with each other. My question is, what is the better way of dealing with more than two threads, when all the threads need to interact with each other. Should I pick one thread as the ultimate parent, say the data thread (I pick this one, because it seems to me this thread will be the most free.) Then have the calculation thread and the UI thread children of the data thread. Then when I have a need for the UI thread to explicitly call the calculation thread, I do this through a function in the data thread.

View 2 Replies







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