Classes Are Single/multi Thread?
Dec 17, 2009
i know that a single function could not be run until it has finished and is currently not running. what if i have 2 functions within a class, are both of them allowed to run simultaneously? or will running 1 of them prevent both of them from running until it is done?(assume that backgroundworkers and threads are running the functions of this class)
EDIT: plus what if a single function has multiple signatures, is it considered a single function or 2 different functions? could both of them be running at the same time or only 1 is allowed to run between the 2 at any one time?
View 13 Replies
ADVERTISEMENT
Jun 13, 2012
How can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:
Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()
[code].....
So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:
interface.Economic.MyMethod
interface.Currency.MyMethod
etc
This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.
View 23 Replies
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
Oct 11, 2011
As we know, one STA UI thread creats the controls only canbe accessed in the UI thread in Winform application. And we need to call control.invoke or begininvoke to run the code in the background thread.
Yes, below code in VB.Net , VS 2010 Winform project can throw the exception "Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on."
[Code]...
View 9 Replies
Dec 23, 2009
Say I have a code with 3 methods that do some pretty intensive work. Would executing these methods on 3 seperate threads be faster then executing them one after the other on a single core cpu? And what if it's a dual core or HT?
View 8 Replies
Nov 14, 2009
I am getting this exception: Cross-thread operation not valid: Control 'TextBoxOutput' accessed from a thread other than the thread it was created on. in a VB 2008 Windows Forms application that I havent specifically made multi-threaded. I have create a sub called Out() like this:
Private Sub Out(ByVal inString As String)
Me.TextBoxOutput.Text += (Me.TextBoxOutput.Text & inString & vbNewLine)
Me.TextBoxOutput.SelectionStart = Me.TextBoxOutput.Text.Length
Me.TextBoxOutput.ScrollToCaret()
End Sub
and I call it from various events to log messages I am getting from my pbx, which I use a third party open source dll to access. The interesting thing to me is that if I run the deployed application (ie, not in the VS IDE) I do not get any exceptions, it's only from within the IDE.if I add the line: Control.CheckForIllegalCrossThreadCalls = False to the form's constructor, the exceptions stop, but a) this seems like a hacky way to get around the issue and b) the application seems to hang sometimes when I have it set this way.
View 2 Replies
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
May 7, 2011
I'm trying to dive into what I consider a deeper end of VB.net to see how far I can go with it. I have a project created, ironically called "My First Server". The aim of this is to create a server which can handle multi clients but additionally isn't the commonly shown tutorial setup of a console application. So it is created as a Windows Form application. The main form (Public Class PrimaryForm) consists of only one control which is a listbox control. This is named LogOutput.
[Code]....
View 7 Replies
Aug 27, 2009
Raising events in multithreaded classes?
I am running a class(gamepad handler) that uses many child threads to check for key input and the like then it raises events to my form to sort out the needed reaction, Is there a way to make the event raises on the same thread as the class itself.
View 3 Replies
Apr 22, 2010
I had followed the Example on mulit-thread in MSDN, but add a loop in my implementation. But seems like the multi-thread is not working.
Private
Sub
SboE_Start_Btn_Click(ByVal
sender As
System.Object,
[code]....
View 1 Replies
Oct 19, 2010
I'm experiencing an error which complexity and way to approach I can't quite understand.. It looks like two threads not able to work simultaneously.The first thread is the normal program thread, and the problem occurs when the user clicks a button. This sends some messages through a method (PlaceOrder) of an API library object. This method is called 2-3 times in a loop. Handlers have also been added (on program startup) to receive callbacks on events raised by that object, and this is the 2nd thread that contributes to the error.
The error seems to occur when the PlaceOrder method is called while receiving an event from this same object.The result is that the UI freezes. I can trace the error in two places. If I trace the first thread (which is the initial program thread); the freeze occurs when reaching the lock(this) line, in the API-object class. If I trace the callback event, the handlers of this event try to invoke a RichTextBox on the form, and the freeze occurs on the line <RichTextBox>.Invoke(....), as indicated below.
The thing is that when pushing the button, there is a loop which calls the method of the API-object 2-3 times. And the first time succeeds, but the 2nd time it seems to crash in some way with the callback. It would be nice if I had made some silly mistake with the invoke code, but I don't think I have, as it updates fine prior to the error.. I'm not sure, but it may be relevant that it's in fact the same object, so early in my program I add this event listener (which is the one that updates the RichTextBox):
AddHandler ibclient.Error, New EventHandler(Of ErrorEventArgs)(AddressOf client_Error)
..while later, related to the freeze, I have:
ibClient.PlaceOrder(....)
But I'm handling a lot of calls forth and back other than these, and haven't experienced any problem before.it doesn't give any exception or error message, it just freezes.The invoke stuff in the form code, which should be as per trusted examples: (Freeze occurs at blue highlight)
Private Delegate Sub SetRichTextBoxInvoker(ByVal message As String)
Private Sub OnLogUpdate(ByVal message As String)
If Me.rtbTwsMessages.InvokeRequired Then[code]........
View 9 Replies
Feb 8, 2011
How do i go about multi-threading that, it's just an example project, so i can try and learn from it. As i'm having a hard time understanding JMC's tutorial as it doesn't directly relate to what i'm trying to do [code]When you hit 'Start', the start button is disabled and the Label1 then changes to "Downloading".The data is then downloaded and put into the Textbox1.Label then reads "Complete" Start button is enabled.
View 5 Replies
Oct 22, 2009
I'm using VB.NET. I want to build a large List (Of MyClassOrStructure) that becomes static after its initial population.I'm going to have multiple threads that need to iterate through this list to read data (no writing, inserting, or deleting)
Are there any very bad things that I need to keep an eye out for?
View 3 Replies
Mar 21, 2010
Developing an application that will serve as an application server (Similar to 'Run Advertised Program' that is present in Windows Server). The downside to using Microsofts current system is that it a) requires Windows Server and b) Works only with systems setup in a proper Domain. I have a number of systems in my house and I'm fed up of downloading from the net or setting up network drives etc etc. I've tried using the code in a similar topic posted a few threads down, but it obviously doesn't support multiple client connections.
View 9 Replies
Feb 29, 2012
Has anyone any ideas of what these errors mean and how to fix them?
Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments[code]...
View 3 Replies
Jan 21, 2012
this is my first post and my knowledge of Visual Basic is still in its infancy (this is my first real attempt at app that is any use) however I am trying to develop an application to delete user profile and home directory folders.
I have the application working but the problem is with the application hanging (I understand this to be due to it running as a single thread and the main form gets ignored while the deletion is occuring) during the deletion process, I have tried various ways to resolve this such as starting the delete procedure as a new thread but cant get it to work without the hang.
[Code]...
View 1 Replies
Jun 2, 2011
i want to process a list of strings using multiple threads. the first function pases it, it then send the result to another, and finally that one displays the final result in list view
dim items as new list(of string)
private sub button_click()
start parsing thread
threadParse = New Thread(New ThreadStart(AddressOf startprocess))
threadParse.Start()
[Code]...
View 7 Replies
Mar 17, 2009
I have an application which is working. Basically you put in the PC name/ip and it returns the logged on user. I am happy with this part. There is also an option where the program can read a text file of PC's. It will then create another text file with the name of the logged on user next to each pc. This part works, however the program is non-responsive during this time (there is a progress bar, so you can tell it hasn't stalled). I would like to multi-thread this part of the app if possible, Just starting the related sub procedure as a different thread would be a great start - I'd like to start a new thread for each pc in the list to be scanned (if this is recommended) however I imagine this might be slighly complicated...The part I'm referring to is the Sub Procedure "ReadFile". This then calls the Sub Procedure "CompareUserList".
View 2 Replies
Feb 3, 2011
2. FunctionLayer -deals with Common Operations which get results from DataLayer and return results to Forms.3. User - deals with User. (For Reusing the User Class in other projects, i have separated this class)Here in Class2 - I have an instance of Class1( ie., DataLayer) for DB Operations.imilarly in Class3- I have an instance of Class1( ie., DataLayer) for DB Operations.Now in my form, If i create Instance of Class2. But When I need user functionality in this form, I have to create an instance of Class3 to this form.
View 6 Replies
Mar 10, 2010
I'm trying to multi thread for first time and I'm getting this errorError1Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(start As System.Threading.ParameterizedThreadStart)': Method 'Private Sub WebBrowser1_DocumentCompleted2(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)' does not have a signature compatible with delegate 'Delegate
[code]....
The code works fine without multi threading?
View 1 Replies
Nov 29, 2011
I was going to hijack another, related, thread to ask this, but I figured it derserved its own thread.The question I have is whether or not anybody has done sufficient testing to show whether a mutlithreaded program running on a multi-core system will spread the threads across all available cores, or whether it has some affinity for the core used by the main process (UI thread, or whatever it may be)? The reason I ask is because I remember a discussion over in General Computing where somebody showed that, for at least one case, all the threads were splitting time on a single core of a multi-core processor. I am wondering if that is the typical behavior, or an isolated case?
View 23 Replies
Mar 15, 2011
i want to use multi thread facility to fasten my calculations. My code is the following:
[Code]....
I am addding items into "string.list" until it counts to 1.000.000. Then i do some calculations in "for each" and "sonuc_listesi" only returns one string. After that; i insert that string into the table in sql. finally i clear both the "sonuc_listesi" and "string_list" to do the new items.
i want to do this with multi thread. For example; when "string_list.count" is 1.000.000; it will be divided into 4 thread working at the same time having 250.000 items individually and inserting their own result (one string) into the table in sql after the calculations. Then each will clear their own "sonuc_listesi" and "string_list". If one of them finishes earlier; it must wait the others get finished.. i hope i clarified well. How should i do this? Is tihs current method is structurally enough to do thread or should i make sub or function?
View 2 Replies
Sep 18, 2011
this is going to be hard to explain but ill try. Question 1. Ok i have a list box with a few items, What i want for this example is to click a button and it will start on the first item and do: MsgBox ("this is item blah blah blah") then after that it will go to the next item and do the same and then the next and so on untill all have been done. The "blah blah" should be the item so if item was to say "hello" then the msgbox would say "this item is hello" I know this would be a lot of msgboxes to close, like if 50 items then thats 50 msgboxes to close, this is just for the example.
Question 2. Ok this is where ive tryed to learn but find it really hard (multithreading) Im wanting all to be multithreaded so all work at the same time, ive tryed a few times but the only way i see it is having a **** load of subs, like if i want it to use 10 threads then ill have to add the same code 10 times or somet, im not sure.
i have attempted all this and failed big time as my way was to get the first item and use that then remove it from the listbox BUT... with it being quite fast the 2nd 1 and 3rd 1 used the same item befor it was removed and to be honest i dont really want them removed. so my attempts took like 2-3 days that was a waste of time really. I Know this is a lot to ask but im in real need of it and these 2 things have driven me half mad.
View 21 Replies
Feb 21, 2012
I want to make my client & server fully working. If a client connects to the server it should tell that there is a new client connected. if a client disconnects it should tell me a client disconnected.[code]it says in my patcher window(where it should add the text) that it's succesfully connected.but at the server side its not saying there is a new client connected/disconnected, how can I do this?
View 2 Replies
Sep 6, 2009
I am still learning VB and operating VB 2005 for school. Challenging issue recently arose and would like advice from someone smarter than I .... When writing code to query several elements from a user,such as: Street number, street name, city, state, zip ... all posed as individual response questions. I want the ultimate displayed answer to show in a single line. When I write to code for that, I get the response in a single line, but they are all jammed together in the cout result screen display, with no spaces between answers (e.g. 2118Winona AveMontgomeryAlabama36102). I want a blank space to display between elements (e.g. 2118 Winona Ave Montgomery Alabama 36102). How do I cause the result line to include spaces?
View 4 Replies
Mar 27, 2012
For downloading a number of images I'm making DownloadDataAsync calls to separate instances of WebClient, in a loop, with a thread sleep delay. I expected the response to happen on separate threads, but it seems not, as response only occurs after all calls are completed.
So what's an appropritate fix for this? Is there an alternative client type, or should I make a thread for each webclient call?
So currently I'm calling this in a loop:
Private Sub StartDownload(ByVal webImageLink As String, ByVal token As Object)
Dim wc As New WebClient
Try
[Code]....
View 1 Replies
Aug 25, 2009
I looked around the site and the questions I found relating to this subject were for C# (the application that I am maintaining is written in VB.NET), so I apologize if I overlooked one. Here is where I am calling my thread:
[Code]...
View 5 Replies
Mar 10, 2010
VS 2008 Multi Thread Overload resolution failed
View 10 Replies
Apr 21, 2009
I am creating an IDE for a game script with similar functionality as the Visual Studio IDE (at least, some of it). The game script consist of code that looks visually a bit like C code. It uses braces to define the start and end of a 'class' and uses nested braces to define the start and end of an 'event' in a class.
What I want finally is to have two Comboboxes above the text editor, one that lists each Class and the other listing each Event. The comboboxes should also show the Class and Event that the caret is currently in, just like in Visual Studio.I have attached an example of such a script (you can open it with Notepad).However, here is a short example where you can also see how I "defined" classes and events:
class1
{
event1
{
[code]....
As you can see, the classes are the 'names' of each block of code, defined by matching braces { }. The events are the names of each nested block of code, also defined by matching braces { } but inside a class. There is only one level of nesting.As you can also see, the layout can follow the standard C-style layout, or a slightly different layout (using the opening brace on the same line as the class/event name), or even a completely chaotic mess. As long as the braces match correctly, the code is valid.So in short, the large blocks are classes, while the nested blocks are events.
What I want to do, is parse an entire script, and store all the Classes (and eventually, also all the Events, but let's forget about them for now). I want to store the Class name, start position (defined as the start index of the name), end position (defined as the index of the closing brace) and the full text (defined as the text between start and end position, so including the name).
vb.net
Public Class clsClass
Private _Name As String
[code]....
The code works basically by finding every first opening brace (the opening brace of each CLASS, not event), and then loops through the class (using a brace counter to keep track of the nested braces) until it found the last closing brace. It then stores the name, start, end and fulltext in a new clsClass and adds it to the list to return.
View 3 Replies
Feb 2, 2012
What type of collection should I use to store data from a table (in a book) that has multi-dimensional Keys to get a single value result?
What is the best way to store and retrieve these values in a program?
View 9 Replies