Way To Load Multi Sockets And Threads?
Mar 8, 2010I'm trying to figure out the best way to go about loading and using thousands of sockets at the same time.
View 5 RepliesI'm trying to figure out the best way to go about loading and using thousands of sockets at the same time.
View 5 RepliesI 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.
I'm trying to get a VB2008 multi thread application working that connects to a local server program using sockets. Server requests for this particular system can be more quickly handled by a number of connections, so I've written some code to run any number of data request threads that I choose. The problem that I'm having is that the data returned from the server is getting mixed up and is often returned to a different thread/socket than the one that requested it. Other than that, it seems to work okay. If I use just one thread, then the system works as it should. Pls. see incuded code, which is heavily edited to remove all the other fruit salad. Is there any way to set up the sockets so that data returned to the socket/thread that requested it?
Module StaticDeclarations
Public WithEvents g_SD As New SocketDataClass(New MainThread.MTCallback(AddressOf MainThread.MTResultCallbackSub))
Public WithEvents g_MT As New MainThread(New SocketDataClass.SDCallback(AddressOf SocketDataClass.SDThreadResultCallbackSub))
[code]....
ok here is my code :
[Code]...
What's happening is, i see the threads stop after the function dwnld is completed. So i first check for the state (12 means background and unstarted). On case 12 start the thread and in case 16 (stopped) remove that particular thread and add a different thread like i add 10 above. Also there is a check when the i counter reaches last number, restart the whole loop by assigning i=0.
The program downloads some web pages, the url is passed from the listbox2. The geturl will pass the url and remove it from the list. So when the listbox is empty, exit the for loop. But the above code is running for only 11 times and it does not restart. I tried using a lable and goto but it simple hangs. What i want is to maintain 10 threads to keep downloading the web pages and when the list is empty, exit the function.
In one of my multi threading programs I cannot get my threads to abort. I have about 5 threads and the threads starts one at a time. By the time the fifth thread is started the program gets really slow. The program will not execute pass LoadWheelStn1.
Code:
Private Sub LoadWheelStn1()
If sPortOpenFlag = "T" Then
Dim MyThread1 As New Thread(AddressOf ThreadStn1)
[CODE]............
I am using vb 2005
I started a threading project and want to manage my code so that it waits for all the threads to be finished before displaying to the user on the main UI thread that it has completed the task and waiting for the user... I've created a List to manage the threads and a global Boolean, "blnStop"...
[Code]...
I'm simulating some threading in a Windows Service, and the Thread.Start routine for each of my threads points directly to the following:
Private WithEvents CheckForOrdersTimer As System.Threading.Timer
Private Sub timerCheckForContracts_Tick(ByVal stateInfo As Object)
' Ticks every 5 seconds, then spawns threads until we're at our max
Do
[code]....
the threads aren't even doing anything yet, but with more than two threads running at the same time, my processor (Core 2 Duo 2.4 w/ 4GB) gets pegged and Windows gets really sluggish. According to what I've read, Thread.Sleep shouldn't be consuming any resources at all while it waits, but it may as well be running in a tight timing loop.
EDIT: Per the requests, I've expanded the amount of code I'm using. I was initially doing some database work before spawning each thread, but I've removed it and the processor maximization still occurs with just the code here (and, of course, the OnStart method for the Windows Service.
I'm simulating some threading in a Windows Service, and the Thread.Start routine for each of my threads points directly to the following:
Private WithEvents CheckForOrdersTimer As System.Threading.Timer
Private Sub timerCheckForContracts_Tick(ByVal stateInfo As Object)
' Ticks every 5 seconds, then spawns threads until we're at our max
[code].....
I've been writing multi-threaded applications for a couple of years and have started reading about the Task class. It looks like it handles mutex and synchronous/asynchronous threading in an easier to follow fashion. I was just wondering if you the community likes writing threads the old way or the 4.0 tasking applications. Lastly, I thought multi-threading was parallel computing. But I was reading that there are special task etc. parallel functions.
View 2 RepliesI'm trying to make a multi-threading app which extracts the names from my site. I have 1000 pages celebrity related. The urls are on a listbox List1 and the number of threads are specified in TextBoxThreads I would like each thread take care of a coresponding url on list, when they finish go to the next one and so on (for each thread a url)
[Code]....
i've searched and searched on here for an example and couldn't find one... basically i'm new to vb.net and learning how to multithread now.i understand threading like
Dim Thread1 as New System.Threading.Thread(Address of workclass.Function)
but how would i do this with a designated value (integer, updownbox, etc.)?
Dim Threads() as New System.Threading.Thread(Address of workclass.Function)
I've only dealt with firing a single SQL statement at a SQLServer table and returning a single result... easy....
however....
is there a way to fire a dual sql command and load the results into respective tables within a dataset?.. I'm thinking something along these lines (this code of course does not work)
Dim ds As New DataSet
Dim dt1 As DataTable = ds.Tables(0)
Dim dt2 As DataTable = ds.Tables(1)
[Code]....
I have six textboxes that need to have the text saved/loaded. They all have random line amounts under 28 if this info helps at all.
View 7 RepliesI 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?
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.
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?
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 Repliesi have one project with multiples web services so i created various singleton class thinking in
performance. now i think create one singleton class and that have the instances of my webservices
[code...]
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 RepliesI am writing an application which involves reading xml over socket. The messages arrive at socket asynchronously. How can I ensure that data is received in form of complete xml elements, validate received data and which classes will be helpful for me in accomplishing my goal.
View 1 RepliesCan i implement PTP (precision time protocol) or NTP (simple network timing) with sockets?
If so, how can i use them to send small packages (4 to 33 bytes) with the smallest delay possible?
P.S. I would prefer to know more about PTP, I've heard that it has smaller delay.
I have an application in vb.net which will connect with an hardware device and test its functionality. The hardware device basically spits out data continuosly through Ethernet. That is it recieves some data via com ports and spits out the processed data via ethernet.So my application does both. Thats pretty much the entire app.My problem is i am using tcpclient sockets. Now when i connect a tcpclient to the device using
tcpclient.open(ip,port);
Immediately the device sends some data which comes and get stored in the clientsocket. Then i send a command to it ,only then i read the data from the clientsocket using
tcpclient.getstream().read()
at this time the entire data that is the one which flowed immediately when connected to the device and the one that i actually need after passing command is both acquired. This is undesirable. I need the data which i read only after sending the command. So i was wondering if there is any way to clear the tcpclient socket before we do a read. The manual doesnt show any such method.
Here is an issue with a socket I am having:
Public Sub Connect(ByVal server As String, ByVal port As Integer)
Dim IP As IPAddress = IPAddress.Parse(server)
Dim EP As IPEndPoint = New IPEndPoint(IP, port)
[Code]....
The socket is declared like this, at the top of the code:
Dim sock As Socket
What is wrong here? It says Object reference not set to an instance of an object, which is a NullReferenceException.
I am using Nektra's Deviare to hook winsock's send method calls. My ideia is to learn to also send messages through the same socket than the original application. So what I'm doing is when i detect the first call to send message, I save the socket id(the first argument of the send function), so I can use it later.
So here is my code:
uint socket = 0;
[DllImport("Ws2_32.dll")]
private static extern int send(uint socket, string buf, int len, int flags);
[Code].....
This last messagebox is poping up always -1. Why should be it?
edit: calling WSAGetLastError() returns 2. Which I do not know what it means, as it doesn't seem to appear on msdn.
i am using vb.net and i would to send some structs to a C++ tcp server.The problem is the structs i am sending might contain other structs.[code]Lets say i want to send FirstStruct over to the C++ Server.
View 2 RepliesI am actually new to VB.net...i have managed to create Sockets and communicate over them..but i dont know how fire sql queries through sockets as they take in Byte data as a input...i want to actually pass queries through sockets and retrive those results...i am using mysql database....i have actually tried changing the connection string (the ip address) for a static network but i think sockets are better for dynamic ip networks.
View 1 RepliesNet.Sockets wait for streamwrite?
View 2 RepliesThis code will allow you to send Emails using only .NET Sockets. This code was adapted from sample code on[code]...
View 7 RepliesSo basically I would like to know what goes on behind smtpclient, webrequest and all those.
I would like to know if its possible to connect to an smtp server with sockets. Also, can anyone recommend a good OOAD(object oriented analysis and design) tutorial or book?
I know there are lots of examples here on the forum, but all to difficult to understand.I have a client:
I have a client:
Imports System.Net.Sockets
Imports System.Text
[code].....