Dart Home | PowerTCP Sockets for .NET | Custom Development | Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
Author | Forum: PowerTCP Sockets for .NET (Secure and Standard) Topic: controll arrays |
dropperk scurby66@aol.com From: los angeles, CA USA Posts: 4 Member Since: 02/12/03 |
posted February 12, 2003 8:06 PM I want to make an array of tcp controls that all run in their own thread. I know i cant do Private WithEvents Tcp1() As Tcp I cant use "withevents" with an array so i will not be able to add code to each callback event from each tcp control. Is it best then to make an array of tcp as Private Tcp1() As Tcp and not use the callback events? Each tcp wont run in a seperate thread then and i will have to run each in my own thread. Does this seem like a good idea? |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted February 13, 2003 5:30 PM Hi, If you use the components asynchronously, they will each run in their own thread. You can create an array of the components, and then use the AddHandler keyword to hook in events. In the simple example below, I have a single event that handles the ConnectedChanged event for each of the members in the array. Hope it helps, -ken Dim Tcp(4) As Tcp Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To 4 Tcp(i) = New Tcp() AddHandler Tcp(i).ConnectedChanged, AddressOf Tcp_ConnectedChanged AddHandler Tcp(i).EndConnect, AddressOf Tcp_EndConnect Tcp(i).Tag = i.ToString Tcp(i).BeginConnect(MY_ECHO_SERVER, 7, "", 0, Tcp(i).Tag) Next End Sub Private Sub Tcp_ConnectedChanged(ByVal sender As Object, ByVal e As EventArgs) Dim s As Tcp = sender Debug.WriteLine("CONNECTED CHANGED FIRED FOR INDEX " + s.Tag + "!") End Sub Private Sub Tcp_EndConnect(ByVal sender As Object, ByVal e As ExceptionEventArgs) Debug.WriteLine("END CONNECT FIRED FOR INDEX " + e.State + "!") End Sub |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted February 13, 2003 5:40 PM Hi, I modified the example above, so that it actually uses the components asynchronously. -ken |
dropperk scurby66@aol.com From: los angeles, CA USA Posts: 4 Member Since: 02/12/03 |
posted February 18, 2003 1:30 PM perfect, thanks! |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted April 14, 2003 1:27 PM Okay, taking this a step further... When doing this, I quickly run up to the maximum threads limit of 25. I am creating an array of 40 Tcp objects and calling BeginSend() on all of them. The first 25 start up and the rest block. What's the best way to get around this? Simply increase the default to, say 50 in Win32ThreadPool.h? Christopher |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted April 15, 2003 11:05 AM Hi Christopher, Yes, there will be a limit to the number of active threads, and it is system related. I do not know if changing that file will have any effect. What happens when you try it? Thanks, -ken |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted April 20, 2003 1:18 PM Turns out that the file is only the definition for the appropriate delegate to change the default thread pool limit. There is no documentation anywhere about it. So my problem is thus: I open about 250 async sockets to a number of sites and ports, and do a BeginConnect on each one. The first 25 (or so, depending on whether I have other async threads running) do their thing, and the rest BLOCK until the first 25 are done. This is clearly unacceptable. I need to get around this. It would appear that the Dart library is relying on the OS IO completion threads and, as such, hitting this limit. Why don't you guys implement your own thread pool for the objects? Failing that, send me source and I'll do it - otherwise, I'm stuck. Christopher |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted April 20, 2003 5:13 PM As a followup - it appears that the problem is not I/O completion threads, but worker threads. I presume, then, that the Dart library starts a new worker thread for every async call? If so, I've resolved the problem by setting my maximum number of worker threads to 250 (instead of the OS default of 25). Now things run so fast, my UI thread can't keep up :-) Christopher |
Alex Gladshtein![]() From: Rome, NY USA Posts: 131 Member Since: 12/27/00 |
posted April 21, 2003 9:43 AM Hello Christopher, I am glad you were able to solve this problem. Did you use the CorSetMaxThreads property to change the default thread limit? I am curious as to the approach you took so that other forum readers can benefit. Thanks, Alex Gladshtein Dart Communications |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted April 21, 2003 5:41 PM Sure. Take a look at the Thread Pool Control Sample located at the all around great collection of sample code site, http://www.bearcanyon.com/dotnet I changed the maximum from 25, 1000 (Worker and I/O) to 200, 500, and things now run great. Christopher |
frodo_x From: unknown, Greece Posts: 8 Member Since: 06/10/01 |
posted May 5, 2003 3:57 PM Hello all.anyone has a vb.net code on how to change the CLR-managed thread pool limit? thanx :-) |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted May 6, 2003 9:32 AM Hi, It looks like the link in the post above has a Thread Pool Control sample which would do this (you would just have to translate from C#). -ken |
riazbordie From: London, United Kingdom Posts: 5 Member Since: 12/29/04 |
posted December 29, 2004 6:12 PM Hello all, Just a quick question with regards to the thread pool max count. Would I be right to say that I need to set the max count to a new value each time I start my server app? i.e: I cannot set this max count on a computer once and for all, without the need to do so again. Please let me know. Thank you. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted January 5, 2005 1:31 PM Yes, that is correct. It is per-application. |
MartenKL From: STOCKHOLM, Sweden Posts: 8 Member Since: 03/03/05 |
posted March 3, 2005 11:15 AM The link above seems to be out of date, can anyone tell me how to change maximum threads per processor in the threadpool? |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted March 3, 2005 11:18 AM It's not out of date. Look at the "thread pool control sample" which has the answers you seek. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted March 3, 2005 11:24 AM Thanks Chris, but actually it was. Ken just went in and edited the post so it points to the correct page now. The link you had originally posted took you to some generic page. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted March 3, 2005 12:37 PM Oooohhhh, gotcha. Switching the link out from underneath me, huh? Apologies, I'd not noticed that had happened. Maybe you guys should grab that snippet of code and put it in your FAQ? |
MartenKL From: STOCKHOLM, Sweden Posts: 8 Member Since: 03/03/05 |
posted March 3, 2005 12:55 PM And please convert to vb, I have done a semi-solution for now where I keep the library in c# because I didn't know how to write it in vb. It works well but vb support for unsigned integers is lousy at best, forget any math operations. I could of course supply the code I have written for setting and retreiving MaxWorkerThreads... If you please give me better control over the threads created by the servercomponent. Thanks everyone for all help. |
Bodekaer From: Holte, Denmark Posts: 21 Member Since: 04/02/04 |
posted March 29, 2005 4:11 PM Yeah, a VB example would be nice. I have tried to convert it, but keep getting an error when VB is trying to initiate the classes. |
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
![]() |