.net - How Many Threads Can Run Concurrently
Jan 28, 2011
I can only run "so many" threads concurretnly, a notion which I have seen elsewhere.As a threading novoice, how can I determine the maximum number of threads to use? Or is this a "how long is a piece of string" question? What does it depends on? Hardware config or what?
View 4 Replies
ADVERTISEMENT
Jan 6, 2010
On a Form, I have button which, when clicked, creates an instance then Shows another Form. If this button is clicked a second time, a second instance of the other Form is created and displayed.However, the first instance then becomes invisble - it still has an occurence in the Task Bar, but is not visible on the display.
Using the Taskbar, one can select either instance of the Form and that instance displays correctly, but, only one instance is visible at any given time (the windows are at different locations on the display and are not hidden behind other windows). What needs to be done to have both instances visible at the same time?
The computer is running Windows 7 64 bit - I don't know if this problem is present in with other Windows versions or not). Here's the code that responds to button click:
Private Sub btnPermissions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPermissions.Click
Dim PermissionsObject As New Permissions
PermissionsObject.Show()
"Permissions" is the Name of the Form, which is in the same Visual Studio 2008 Project as the Form with the btnPermissions button.
View 8 Replies
Oct 26, 2009
I'm writing something to download about 200 small (Around 200kb) files at a time. I pass the file urls off to a class which starts the downloads. The problem is that it'll start the download (Just creates a 0kb file) and then slowly downloads each file one by one, waiting for the next to complete despite this being a threaded class. This would be fine but after about a minute, windows removes all of the 0kb files and I'm stuck with only a few of the files being downloaded. How to get multiple files to be downloaded concurrently?
Imports System.Net
Imports System.IO
Public Class DownloadClass
Public downloadUrl As String
Public folderURL As String
[Code] .....
View 6 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
May 18, 2011
I want to perform two hashing operations concurrently on a single file, without reading the file twice. Is there some way to share the FileStream between two synchronized hashing threads? For example:
Dim Stream As New IO.FileStream("...", IO.FileMode.Open)
Dim HashA, HashB As Byte()
Dim A = New System.Threading.Thread(Sub()
[code]....
Maybe some way of caching a stream? Trouble is, I don't want the entire file in memory at once (it could be many gigabytes in size) and I don't want the file read more than once, due to speed issues. I want the file cached only sufficiently to ensure that both threads can work.For example, suppose at some point in time, thread A had read 100k of the file, but thread B had only read 20k of the file. The portion of the file between 20k and 100k should be cached; but then progressively forgotten as thread B catches up. Then again, if thread B is too slow, we might still end up with hundreds of megabytes being cached.Maybe thread A should be made to wait while thread B catches up. Maybe the ReadByte() function of the stream should block for a while if one of the threads is too far behind?
View 13 Replies
Dec 14, 2009
in my button click event i ececure
If BackgroundWorker4.IsBusy Then
BackgroundWorker1.CancelAsync()
End If[code]....
after proceess completed if press the button again.i got the following error msg
This BackgroundWorker is currently busy and cannot run multiple tasks concurrently.
View 6 Replies
Sep 14, 2011
I need to run TWO Threads in a web application, .NET. 3.5 Both methods MakeRedCars and MakeBlueCars need to run at the same time as both take 5 seconds. I have tried many example codes with very bad results. I dont need anymore than 2 threads. The main issue I am having is knowing how to wait till they are finished and also how to store the results from each.Each of the Methods do different things, one is a web request, one is a sql call.
Both methods return a list of(cars) for example do:
carList.addrange(MakeRedCars())
carList.addrange(MakeBlueCars())
for each car in carlist<br>
response.write(car.colour + "<r>")
next
I have implemented the answered below and with empty objects all works well, as soon as you hook in a database call that returns the data/objects studio does a JIT and crashes.
View 5 Replies
Apr 18, 2010
it would be best if I just copy and pasted the code (it's very trivial).
Private Sub Main() Handles MyBase.Shown
timer.Interval = 10
timer.Enabled = True
End Sub
[code]....
An exception, "The object is currently in use elsewhere", is raised during the tick event.
View 1 Replies
Oct 25, 2010
I am having an issue where I need to implement a type of thread scheduling... I'm looking to implement a list of tasks, each with a set time that they need to execute, and after the time is up they will execute the respective code that goes with that task. I would use a timer based solution, however, I don't think that it would be very efficient. There will be a very large list of tasks, some of which need to be executed within seconds of being placed in the list.
View 1 Replies
Jun 10, 2010
I have 2 thread.One that put some data inside a list?the second that take out these data from the same list.what is the best "list" that allows one thread to put something inside and another one that take stuff out>
View 1 Replies
Nov 7, 2010
My application generates some background threads to perform some slow jobs (a cycle of ask for a long process to a server - wait - download the result).
View 5 Replies
Feb 25, 2009
I'm having a bit of an issue killing threads off and resetting my form. After starting the threads, everything runs fine. When I want to cancel the threads, the threads are all killed off "properly" using the Abortable Thread Pool, but how do I know that all the threads are dead? I've tried using both GetAvailableThreads and GetMinThreads compared against the thread count that should be running if they're all killed off, but I can't seem to get it to work. The only time I can get the GetAvailableThreads to return the "correct" number is if I freeze one thread and kill off the rest.
View 7 Replies
May 28, 2010
I have a GUI that is running for a form, let's call it Class xWindow. It has finished processing data and is simply waiting for the user to press a button, i.e. the main thread has nothing to do. Just before it finished processing, it kicked started something that has a callback function which occurs in a new thread (e.g. a system timer or a Bonjour callback to say that a service has been found on a port). This callback occurs within the xWindow class.
[Code]....
View 10 Replies
Dec 22, 2010
Suppose I have created 70 "rule-finder" objects, and I want to run each one on data.This is a time-consuming process.The new computers with the I7 chip can run 7 processes in parallel, and so I was thinking of running 7 threads at a time. Asone thread ends, I would add another, until all 70 objects are used. When the last rule-finder has completed, I would resume the main course of the program.
View 5 Replies
Jun 1, 2009
how can I let two threads communicate with each other by using VB.net?
View 3 Replies
Jan 25, 2010
I currently have a program that runs several "intense" queries. I added a textbox and presented status updates when a query was starting, eding and how many were left. This would suite my need, but the textbox doesn't actually display anything until all the queries are finished. It then displays all the updates at once. I'm assuming updating the textbox in another thread would solve this issue, and that is where I am lost. How can I use a thread that receives a message from the main form running the query and have it display it in the textbox?
View 4 Replies
Feb 25, 2009
I'm making a Tabbed Web Browser, and I need favorites to add to this web browser, I was searching this forum for answers on how to do it and I ran into some threads tlaking about XML and how they are easily controlled, yet a little more complex. How do I do this? Where do I start?
View 2 Replies
Jan 23, 2011
Take a look at the code below. Here I create a thread, set its name, and start it:
Private Sub fileCreated(sender As Object, e As FileSystemEventArgs)
Dim processFileThread As Thread = New Thread(AddressOf fileCreatedHelper)
processFileThread.Name = e.FullPath
processFileThread.Start()
End Sub
This is the sub that is the thread: Private Sub fileCreatedHelper()
[Code]...
View 2 Replies
Aug 17, 2011
I have a threading problem when it comes to updating the gui from the thread.
In my main function I have the following:
Private Sub StartThreads(Optional OrgName As String = "")
Dim blnMonitorEntered As Boolean = False
[Code]...
View 6 Replies
Jan 4, 2011
In a .NET 3.5 Winforms app, after a user provides a username and password, I set a custom principal in the CurrentPrincipal property like this:My.User.CurrentPrincipal = Service.GetPrincipal(username)This is done in a method that is called using Invoke, because the originating thread is not the UI thread:Invoke(New Action(AddressOf doLogin))But when I click on a button in the Winforms application, the CurrentPrincipal property has been reverted to its default, the current Windows user.Dim lPrincipal = My.User.CurrentPrincipal ' not my custom principalApparently, using Invoke while setting the principal does not solve the problem. Is there another way to set the CurrentPrincipal property for all threads in the application?
View 1 Replies
Jun 26, 2011
i have this code which i run with queued 10,000, even when a max of 50 is set but the threadpool counts goes to high.
Public Sub DoWork(ByVal objItem As Object)
Dim objUrl as String = DirectCast(objItem, string)
Try
If objUrl Is Nothing Then
[code]....
EDIT:i use a this code to check the number of runing threads each second
Sub Timer1Tick(sender As Object, e As EventArgs)
tsslthreads.Text=string.Format ("Threads: {0}", Process.GetCurrentProcess().Threads.Count)
End Sub
View 3 Replies
Sep 28, 2010
I have 2 threads in my Program. Here is code for both of them
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
[Code]...
StartReceiving is working fine but StartWriting is called only once and that msgbox in startWriting is never called, any suggestions on this
View 7 Replies
Jun 16, 2012
My question is to add two numbers up using threads or multithreading. Here is what I have:
Module Module1
Sub ThreadA()
Dim I As Integer[code].....
Is there a way I can use this somehow to add two numbers up?
View 1 Replies
Oct 27, 2010
In my Winforms application, i've got a form and an associated business layer class. All controls are bound. When i click a button i call a method on the class which then starts a background worker and returns. The background worker does some processing and finishes.
The problem i'm having is that i'm using a label to display any error messages generated by this background worker, which is fine but after a set time i want to clear the label, so for that i'm using a timer (on the business layer class), which, when it fires, is on a different thread and thus should not update the property that the label is bound to Whats the best way to do update the label? -- Should i be using a delegate to update the property value, if so how do i invoke it?Note i'm also having a problem with getting the databinding of the visible property on this label to work.
View 5 Replies
Oct 18, 2011
In VB.net, I tested concatenating 100k strings and found out one thread alone did it in 23 milliseconds. Two threads (each concatenating 50k) then joining the two at the end took 30 milliseconds. Performance wise, it didn't seem beneficial to utilize multiple threads when dealing with only 100k concatenations. Then I tried 3 million string concatenations and two threads each handling 1.5MM always demolished one thread handling all 3 million. I imagine at some point using 3 threads becomes beneficial, then 4, and so on. Is there a more efficient way to concatenate millions of strings in .NET?
fyi, this is the code I wrote:
Imports System.Text
Imports System.Threading
Imports System.IO
[code]....
View 2 Replies
Jan 18, 2012
My scenario is that I have a Windows service running as SYSTEM. That means no network rights by default. I want to copy a file from server A and server B. Both require different Credentials.Normally, I use Impersonation on one thread to access another server [URL]. The problem is that one thread can only impersonate as one user. And I need to access server B as well.So, I wonder about the best way to copy between two threads. I am interested in doing this in memory, for speed and I do not want to save a file locally on disk in between.
View 3 Replies
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
Jun 7, 2011
I recently began working on an application that was built by someone that is no longer available. This application is filling an excel file, but I can not find ANY code that uses excel. There aren't even any references to excel interops. My thought is that this a multi-threaded application and I can't see what is going on behind the scenes. I tried watching the processes in the task manager, but found nothing.I've never worked with threads before, and do not even know where to begin. Debugging the program with breakpoints at multiple locations does not show me any of these other threads. Anyone have an idea on how to find/debug threads of a program?
View 1 Replies
Jan 9, 2010
Public Class ThreadSearch
Inherits frmStDetails 'Windows form which contains my control
Public Event finishedSearching()[code].....
This is the procedure I used to start the thread. It doesn't generates error but the problem is 'IT DOES NOTHING'.
View 9 Replies