VS 2008 Cross Threads -- Lost In Space?
Feb 5, 2012
Frankly, NONE of this makes sense to me..[URL]..They just jump right into code without baby steps that explain the situation.Every other aspect of VBnet has been well spelled out to me and I get it -- but this business of using the serial port and going nowhere because of a cross thread error has me 100% baffled.
If anyone can point me to a tutorial that really explains it simply and well (without jumping into friggin' code).Even in the above link, they show 3 different techniques of addressing the same problem ! (Like I CARE
View 5 Replies
ADVERTISEMENT
May 4, 2010
this is sumit from Larsen & Toubro Mumbai-India,I am writing a code for some sort of software in which execution of some code is required as soon as my software receive a barcode from barcode scanner (serial input). Now through datareceived event handler i am able to read the barcode but after that i am not able to send this barcode to any textbox or even i am not able to start any other event like performclick to any button or anything. I am getting an exception as cross linking of threads not possible. please refer to the image and give me the solution asap.
View 2 Replies
Apr 5, 2012
I am getting this error: Unable to cast object of type 'SGA.AppContext' to type System.ComponentModel.ISynchronizeInvoke'.I am not using a start up for my project but a sub main() and a threaded class AppContext
View 14 Replies
Feb 8, 2010
My application need to communicate with my self made device through serial port. I have to change the selected index of Tabs when I press a button on my device. I have Form1, Form2, Module1 Form1 Contains the Serial Port Control. Form2 contains the Tab which needs to be changed. When I press a button on device them, the button pressed is stored in an integer form in a global variable.The Interrupt for the Serial Port directs the control to the module1 where I decide using Select Case that what index of which TabControl I have to select.Depending on that, I change the Index of the required Tab.
PROBLEM:cross thread exception is fired as soon as the control reaches the statement where I Modify the SelectIndex property from the select case at Module1.While, on my other PC, the SelectIndex property is changed, but the next tab is not shown.
BUT, if I put all this code in a button control, and try to activate from there, then it works perfectly. However, I have to navigate through the tab controls using my self made device.I searched a lot on net and came across a solution which describes that we have to use delegate function and invokeRequired methods to ensure that the procedures run on the same thread.I am not able to decide that where exactly shoud the code for delegates and all be written, in form1, or form2, or module1.Also, in the hit and try that I did, I always got the value of InvoleRequired as False.
Here is the part of Code that I wrote for Delegates
Code:
'Form 1 is BLINDHELPER_SIGNIN
'form 2 is BLINDHELPER_USER
' I have defined these at Module1
Public Delegate Sub DeleToManageTabs(ByVal tb As TabControl)
Public Sub manage_Tabs(ByVal tab As TabControl)
MsgBox(tab.Name)
[code]....
After using this code also, there is no change in working of my application.
View 3 Replies
Jun 29, 2010
[Code]...
This was the code and this is the thread HERE Ok its working and everything but when i want to perform something when click is noticed it says i cant cross-threads
View 39 Replies
Sep 25, 2011
How would i get a certain text inside a textbox to equal that text space to space or null to space?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Textbox1.Text.StartsWith(Textbox2.Text + " ") And Not String.IsNullOrEmpty(Textbox2.Text) Then
Textbox1.Text = Textbox1.Text.Remove(0, Textbox2.TextLength)
Textbox3.AppendText("a")
End If
Btw: after i finish this step my project will be finished!
View 4 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
Dec 30, 2009
I have a main thread which is designed to be a batch processor - it spawns a series of 'child' threads from a loop (which can vary in terms of the no of items) - see below
[Code]...
However, each of the 'child' threads could take anywhere from milliseconds to about a minute to process - depending on the complexity of each calculation. There may also be a large number of child threads - e.g 100s. Creating large numbers of child threads is not efficient. I therefore want some way to effectively queue each child thread (and cancel if the process is taking too long to complete). Autoevents seems like one way of doing this, but the only examples I can find seem to assume there are two different processes on seperate threads, not one process being repeated.
View 4 Replies
Jun 5, 2010
I have purchased windows 7 today and installed it. The problem is that i lost Visual Studio 2008 Stranded Edition. Were could i download it. I do have the Key that i have purchased from the Microsoft Store. Were can i download it. I have looked on google but i only found the Visual Studio 2008 Professional Edition.
View 29 Replies
Apr 5, 2012
I've made a program. The program does what it's supposed to do, for a while. The program is meant to recover my password if I loose it, but when I test it, it fails. It works fine until it comes to the number of my password. Then this error shows: object reference not set to an instance of an object. And this section of code is highlighted:
HTML
WebBrowser1.Document.GetElementById("ctl03$Login$username$input").SetAttribute("value", TextBox1.Text)
Here is complete Code:
HTML
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dialog1.ShowDialog()
[Code] .....
View 7 Replies
Jul 16, 2009
Is it possible to color the row after it lost focus?
View 7 Replies
Oct 27, 2010
I'm using Visual Basic 2010I've created a ListBox and a BackgroundWorker using designerI want to change the location of listbox using backgroundworker but I get the error as follows:"InvalidOperationException was Handled by user code:"Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on
View 10 Replies
Dec 23, 2010
I was wondering if you could offer a hand on something I'm finding a bit tricky.I am looking at basic shell integration. That is, when a user right clicks a file they can select an option that I have specified. Clicking this will allow them to do various functionality. The way the shell is working for me is that I have a registry entry which runs a specific file. That's all well and good but I need to communicate with a process that is already running on the local machine. (To prevent the users from having to enter login details multiple times).
So I need a way to launch an application, which can call a function in a process that is already running, and pass through the file path. The other application takes the filepath and does whatever it needs with it.
I have both separate sides of the application working (it can get the file path fine, and the other application knows what to do with a file path). The problem I am having is actually linking the two together.
View 5 Replies
Nov 5, 2009
This code is from [URL], so I assumed it would have worked, but I am probably missing something simple.
[Code]....
When I run this code, I get an InvalidOperationException (cross thread operation). How can I get my progress bar on the second thread, or does it have to be created at runtime on that thread?
View 2 Replies
Jan 28, 2010
I'm trying to set the text of a ToolStripStatusLabel in a form, wich contains some ToolStripStatusLabels, a ListBox and a button. I'm setting the text from a BackgroundWorker wich is started from a timer. I thought this would be okay. Well, the problem is that sometimes it works, and suddenly after a while, I get a cross-thread error wich says:
"Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on"
Well, where did the ListBox get involved in this problem? The code breaks on this line:
ToolStripStatusLabel3.Text = "Henter data fra eTime-basen..."
So, what am I missing here? I've never encountered this before in any way. I'm only using the ListBox later in my BackgrounWorker, and each time I'm using it I'm checking the InvokeRequired-property to avoid problems with threading.
View 2 Replies
Oct 2, 2009
I have a loop the iterate in my ListBox and I got this error. Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on.
Here is my codes:
Private Thread As New System.Threading.Thread(AddressOf myFunc)
Sub myFunc()
Dim i As Integer
[Code]...
My Listbox1 is contain hundreds of lines to loop..thats long iteration. and i need the main form keeps responding from other function even loop is under process. This time i need to use this method of multi-threading.
View 6 Replies
Apr 5, 2009
Im trying to work with threading on a project im doing but i have run into this cross-thread problem, ive worked with background workers before and never had this issue.ive done some searching and found some good threads this one in perticular[URL]..now i tried to use these examples and i made it work on a differant project but i cant seem to get my head around how to make it work on this project.
[Code]...
View 9 Replies
Jul 28, 2010
I'm testing here something, but i don't know what's the best way to do this.I have a var that tells the application the number of threads that will be started, inside the thread/function that i call i need to return/get two values i have two sub functions, each one returns an integer.Then in the end i need to sum the values.
Example:
Thread1/Function
SF1 - Returns 2
SF2 - Returns 3
Thread2/Function
SF1 - Returns 1
SF2 - Returns 5
After all threads are over, i get the
SF1Total = 2 + 1 and
SF2Total = 3 + 5.
I'm thinking in using shared vars, and inside the function/subfunctions update the values. It's this a correct way to do it? Other question, the threads are assync, but i need to know when the last one finishes. How do i control this? The order they finish doesn't need to be the order they were called....
View 4 Replies
Mar 3, 2010
I have a process that may take a while, so I decided to put it into a thread and adding some GUI (progress bar) to calm the users down while it's working in the background.The thread itself is working properly.The problem is that the cursor, which I wrapped with a 'sandglass' before using the thread ("Me.Cursor = Cursors.WaitCursor"), has stopped working, and I can't figure out why. When I debug, it's getting inside the function and relevant line - but ignore and do not change the cursor.
Attached is the code, before and after:
Before - working properly:
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetReport.Click
Me.Cursor = Cursors.WaitCursor
If IsValidatedFields() Then
[code]...
View 3 Replies
Sep 21, 2011
VB CODE
Private Sub pstart()
Dim i As Integer
[code].....
View 5 Replies
Apr 9, 2010
I need to 'download' the contents of an XML file that resides on some web address and parse them. I need to do this about once every 5 seconds. I use a HttpWebRequest to do it, but I don't think that's relevant.The 'problem' is that this request + parsing can take a little bit of time, and even more time if internet is a little bit slow. So, I decided to do it in a background thread.I have a method, let's call it GetXmlInfo(), which does all the hard work. Then, I have a timer that ticks every 5 seconds. Now I have two options for starting the thread.Option 1: creating a new Thread object every time the timer ticks:
vb.net
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Dim t As New Thread(AddressOf GetXmlInfo) t.Start()End Sub
[code].....
In option 2, when the GetXmlInfo method has not finished yet, no new thread will be created and the GetXmlInfo is 'skipped' for one timer tick (or possibly more). Could this create a sort of "deadlock" (I know it's not really a deadlock), like if the thread never finishes for some reason?
View 4 Replies
Jun 19, 2011
I work on one project. When i have text in TextBox1 The text is : asddsa123456 I wanna to make text : asd dsa 123 456 Simple to add space.
View 8 Replies
Jul 26, 2009
I have a file search method, but I have a question about it.
THis is the code
Dim MySearch As New FileSearcher("D:", "tomb2.exe", False)
Dim Results As Specialized.StringCollection = MySearch.Results
For Each tstr As String In Results
ListBox1.Items.Add(tstr)
Next
I have other files too : tomb3.exe, and tomb4.exe I'd like to have those to search at once too. I tried "tomb*.exe", but then it didn't find anything.
How can I set the space between tomb and .exe to anything. So it searches all files that begin with tomb and end with .exe ?
View 8 Replies
Dec 3, 2010
I have to do a questionaire that gives three questions with multiple choice answers. When the user clicks a radio button it displays a tick or cross depending whether the answer is correct or incorrect. I also want to display, on a label, the number of correct answers with the number of attempts. i.e 1 out of 3. I have listed the code I have for the questions and radio buttons and I know I have to declare form variables but I do not know how to get it to recognise the radio button as a number to add to the total.
Private Sub radBevan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radBevan.CheckedChanged
If radBevan.Checked = True Then lblScore.Text = "Incorrect. The answer is Beveridge."
If radBevan.Checked = True Then picTick1.Hide()
If radBevan.Checked = True Then picCross1.Show()
End Sub
View 1 Replies
Feb 4, 2012
I'm going to level with you -- although I heard someone say a long time ago "Never use it"! -- and it stuck with me, if I didn't have this in my form load code, my program wouldn't work.Because, to be completely honest, I could never get my head around the issue regarding the serial port and using delegates. (Haven't given up though).
Anyway, the software works absolutely fine with this statement BUT I get a several errors without it based on that "separate threads" thing (to put it in hillbilly terms). is it still "Never use it"? or am I not alone, and some of you have also used "check for illegal cross threads = false"
View 39 Replies
May 22, 2010
I'd like to know what the code is to make a picture box not able to cross a lineshape.
View 3 Replies
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
Jul 29, 2010
In the same line of this thread Now i have a problem with the control of the ending threads. This is my
vb.net threadsEnded = 0 For j As Integer = 0 To numThreads - 1
[Code]...
Some times the application doesn't finish and if i pause the application i see that the threadEnded var doesn't have the correct value, seems like some thread doesn't update the value of the var.
View 5 Replies
Oct 26, 2009
I am trying to get into vb.net but having an issue getting a variable value from a class library in a different thread.
What I am trying to do is create my own Winsock type control for my own use. Once data arrives I try and pass it back to the main application so that I can read it and process it.
So far I cant get it working at all. I have tried the following
Raiseevent
I try passing the value as a variable in the raiseevent property. This triggers an error about the value being in a different thread, I always thought that it would create a new variable in the thread of the application it was raising an event in and copy the value.
Function
I have tried writing a function into the class that I call (much like how the winsock control works) so that the class can return the value to the main application.
aka
strData = Myclass.GetData
in the class it returns the value and clears it from its own local variable. This however means the value returns to the main application as nothing even if I step through and see it assigning a value.
View 12 Replies
Sep 4, 2010
I have a created a class, which contains a sub routine.This sub routine, should ideally be accessable by objects which are not members of the class, so I would like to make the sub, a 'shared sub' (call it Sub1).
Question: I am using many threads and there will be possibly 100s of 1000s of threads all wanting to use Sub1 (which is at present, is not shared).At present Sub1 , is not a shared sub, so every time a thread wishes to use Sub1 , I am creating a (dummy) instance of the class and then applying Sub1, to that instance.
My program works flawlessly using the above technique.Question: If I were to turn Sub1 (which is not currently shared) into a shared sub, and directly had various threads calling Sub1, would there be any issues with locking, ie. would it possible for 2 threads to enter that thread and start overwriting variables, which another thread has written to?
NOTE: there are no shared variables/properties in Sub1 and all variables used in Sub1 are declared within the sub itself.
View 7 Replies