How Would I Multithread This Piece Of Code
Mar 3, 2009On this piece Of code I want to multithread, beginning where the for loop takes the data out of the array arydata. The threads would all do the same task.
View 1 RepliesOn this piece Of code I want to multithread, beginning where the for loop takes the data out of the array arydata. The threads would all do the same task.
View 1 RepliesI am trying to successfully multithread a piece of software I have been working on. I have an array of threads 'gen' already working, calling to a method taking a single integer as a parameter (done via typecasting).Now in this thread, when the function gets processed (for each thread a roughly 500 iteration while loop) the index seems to be getting mixed up. As far as I can tell, my threads are messing with eachother and warping values. Now this is happening in locally declared variables inside this function, not global variables.It may be useful to know that I am using a WebRequest via a call to another method. Don't know if that makes a difference or not.
View 7 RepliesI spotted this ina piece of code I am trying to decipher, and it made me giggle...
Public Const INFINITE As UInt32
Infinity in an unsigned 32-bit Integer.
I am translating a piece of C# code into VB.NET using online convertors..[code]The VB.NET translation is not up to the mark and gives compiler errors Any VB.NET expert who can suggest what to change to make the code compile?url.
View 10 Repliesmy situation is this; I have a search button which searches records with Surnames, when two or more records have the same surname, the first record appears and 4 navigational buttons appear, they are 'Go back to first record' (btnFirst), 'go back one' (btnPrevious), 'go forward one' (btnNext) and 'go to the last one (btnLast)'. All of these work properly except for 'go back one' (btnPrevious). When I click this and the record is currently the first one, the program crashes. Its probably a very elementary mistake but I can't figure it out. Here is the code for btnPrevious
[Code]...
Having read the rules I don't have much code to show apart from these lines I want to have executed just before the program or a form closes.
If My.Computer.FileSystem.FileExists("File.file") then
My.Computer.FileSystem.DeleteFile("File.file")
End if
How can I get the time that a piece of code toke to execute ?
View 3 RepliesI am starting to debudg my application in depth, and have realised that at certian points, if you close what appears to be the only open form, the application stays open. I was just wondering if there exists somewhere, a list of all open forms that you can view during debugging?Alternatively, is there a quick piece of code to close all non visible forms?
For Each frm In Application.OpenForms
frm.Close()
Next
Doesn't seem to work
I have a standard scoring algorithm but I need to help on a piece of code to only execute the scoring algorithm at certain times.I want it to be triggered by dates, but the problem arises if the program is used after 2 (or more) dates have passed, the first date will not be added as the second date is the newest and therefore the one that triggers the scoring algorithm. - The scoring algorithm gets the scores for that week, which are stored in a text file.
View 5 RepliesI have a piece of code which loads either french or english text and 2 link buttons that allow to switch between.
<%
if publierFR = 0 Then
if publierEN = 0 Then
[code].....
This is a very simple piece of code involving threading and events. I am just refreshing the old grey matter as I find myself off work sick for a period of time.
Code:
Imports System.Threading
Imports System.Threading.Thread
Module Module1
[CODE]...
I am trying to insert a piece of html code into a web browser control in vb 2010. i have tried the webbrowser1.documenttext function but cant seem to get the browser to run the html code.
View 7 RepliesHow can I execute a piece of code at set intervals without using functions or timers?
View 3 RepliesI am trying to make a blackjack program and I need to execute a different piece of code each time a button is pressed by the user.
View 5 RepliesI came to a company that already has a fully grown project... but coders that worked here before me didn't follow conventions and didn't use parametrized SQL queries... as a result there is over 1000 places in a very huge project that can possibly be vulnerable to SQL injection...
I need to find a solution that will automatically detect if there is an SQL injection in the code. So, for example there is a form which allows user to enter comments regarding a product, which will be sent to database on submit... how can we make sure that a user didn't enter a harmfull query instead of a normal text?
Is there any advanced code/regular expression/magic that can detect if this text contains a piece of SQL query instead of normal harmless text? I will accept any links, pieces of code in any language or even commercial software that will do that for me.
I'm trying to, from a client-side piece, call off to a server-side piece. I need to do this synchronously. On my server-side code, though, I'm calling off to another piece of code, which I want to have a maximum of, say, 10 seconds to return a value. If I don't have a response within 10 seconds, I want to force my own server piece to set my result equal to 0, and return to the client.
Here's what I have on my server-side code so far:
Public Function GetWebResult(ByVal inputParameter As Object) As WebReturnObject Implements IWebInterface.GetWebResult
Dim result As New WebReturnObject
Dim webItem As WebItem = Nothing
[CODE]...
I realize this code is not functional. The problem is that I'm unsure how I would go about getting back into GetWebResult to set the appropriate return values before it is sent back to the client.
I'm making a type of download manager which downloads parts of a file using HTTPREQUEST.addrange. The parts download without a problem and currently I use 5 instances of the same class to download the parts simultaneously each one downloading a different section of the file. Now my problem is that I don't want to save each part as a file then merge them later, I want to use a singular filestream and append everything asynchronously. In the code below I attempted to use the seek method but it feels like it changes the seek for all of the other parts as well.
[Code]...
how do I multithread using timers. For instance 3 picture boxes that change ever 3 seconds?
View 1 RepliesI have client/server app.I have a class for the tcpclient and a class for the tcplistenerIn my tcpclient class I have a system.timers.timerThe timer elapsed event fires a public event(in the tcpclient class) which the tcplistener class handles.During debugging I see the timer firing its elapsed event and calling raiseevent on the public method, yet the event is never fired in my tcplistener class.
View 1 RepliesI'm working on a project. It is a windows form app which has a webbrowser. The app navigates to a url automatically, checks the url's document, and jumps to another url (depends on the document). It works fine. But, now, the problem is the project needs check many urls, so, I'm trying to make it as a MDI form project. when the start button clicked, it create a control thread, in the thread, it launchs 10 MDI forms (within main form), each form does the work for different urls. once done, then launch the next 10 urls.
It works. However, I noticed that, although 10 MDI forms are open, the navigating part in their webbrowser seems run in sequencial. I thought these 10 MDI forms will load 10 urls at the same time, do the work at the same time, but I found that it seems they do load urls one by one, not at the same time.
so, I did some research, it seems webbrowser can only be run STA mode. does it mean I can not use multithread to load different urls at the same time?
basically, I want to have a multi tab webbrowser, and navigate to different urls in these tabs at the same time.
the differences between multi threading and background worker and when I should be using either.
View 3 RepliesVB and programming on Windows as such. Mostly c++/gcc/linux. I am trying to build this VB app that shows a streaming video from a camera and that needs to be overlaid with some custom graphics and text. I used the code published here: [URL] to get the capture part to work. It essentially uses the avicap32.dll that most of you would probably know.
My plan:
1) Capture frames using SendMessage(windowHandle, WM_CAP_EDIT_COPY, 0, 0) and then copy from clipboard.
2) Do whatever graphics/text overlay on the obtained bitmap
3) send it to some picturebox on some form that is being shown
4) Do step 1 to 3 in a loop by a spawned worker thread.
Firstly is this a reasonable way to do what I want? or is there a much more efficient/easier way to about?
Now the specific problem: From my main thread directly if I do step 1 to 3 once UIComponent.DrawImage(VideoComponent.GetBitmap()) It shows me once captured image as it should and all is good.
Just to clarify: UIComponent is an object/instance that launches the Form and owns the picturebox I want to display on. VideoComponent is an object/instance that has started the videocapture and owns the picturebox to which the video is being captured. But if I wrap the same call above in a function and launch a thread that would start with that function as its starting point, I see a blank screen. Again, for testing purpose, I am only doing step 1 through 3 just once.
The thread part of the code is like this:
Private drawthread As Thread
public sub main()
drawthread = New Thread(AddressOf threadfunc)
[CODE]........
I have this situation: a Form with a System.Timer in it (with AutoReset = False). The form has its main thread and the timer its own thread too (nothing new here). When the user press a button I need to stop the timer, wait until the timer thread has stopped its execution and do something more.
On the other side, the timer updates an item at the form so BeginInvoke is used. The code looks like this:
Button Code: Private Sub ButtonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStop.Click
[Code]...
The point is that I wait the main thread to let the timer thread to end its work.The problem is that this code deadlocks when the user clicks the button when the BeginInvoke is going to be called. How a simple thing like this one can be done? Looks like I cannot find a good solution to this problem
SERVER
Im using this code:
Imports System.Threading
Imports System.Net.Sockets
[code]....
but when i tried to run the application, it hangs even if i wait several minutes.., is there something wrong with the code..
I have a multithread program and in a thread i read a stram from ftp server and write them to a file and close it and in another thread open saved file and read it for process.but sometime when i want to open saved file i receive a error that say : cannot open file , because another user open it .i create 2 filter that surly file saved and closed , but i don't success.
View 5 RepliesI have a program with 3 forms; each has a different role behind them. Form 1 loads when the program executes and the other 2 load by clicking on buttons from form 1. I would like to implement a multithreaded approach where even after clicking on form2 and form 3 I can still execute other form 1 options while form2 and form 3 contents execute. I read through some tutorials and still not to sure how to implement. I figured I need to create instances of the forms 2 and 3 but how to call the threads and control them? I did try a simple one and had some error concerning delegates.
View 4 RepliesThe server connects, the clients connect, one client sends a message to the server, and the server broadcasts it to the other clients. But what I want to do now is to also have the server communicate with the clients. But when I click on the server form, it freezes, and I cant do nothing.
I think this is because of me not creating a thread for the communication(I saw this on another forum), but I dont know how to do that. I copied basically all the chat program code from a site, and I dont know much of sockets and what not.
i'm doing a chat for a project, and it works like this. The server connects, the clients connect, one client sends a message to the server, and the server broadcasts it to the other clients. But what I want to do now is to also have the server communicate with the clients. But when I click on the server form, it freezes, and I cant do nothing. I think this is because of me not creating a thread for the communication(I saw this on another forum), but I dont know how to do that. I copied basically all the chat program code from a site, and I dont know much of sockets and what not.
View 2 RepliesHow can I use a text box on a multithreaded client so that it will appear in the command line of the multithreaded server?We were given this code to work around/tear apart:
Imports System.Net.Sockets
Imports System.Text
Module Module1
[code]....
i am new with multithreading in vbnet. i got this error.Cross-thread operation not valid: Control 'lvSample' accessed from a thread other than thethread it was created on.this is my code.
Private Sub xFormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim t As Threading.Thread
[code].....