|
Ok thanks for your rplies
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
Hi all,
Dose any one know about documentation oF MSPastry Library under MSDN that could be utilized in C# code?
thnaks to you all in advances
|
|
|
|
|
There is no documentation since it's a Microsoft Research project.
|
|
|
|
|
Hey guys
As in the post below I'm busy writing a TCP server. The servers TCP communications are executed asynchronously.
Someone suggested that I take the received bytes out of the asynchronous callback and process it in a separate thread. Lets say I have 100 clients sending data to the server, I can't have 100 threads(one for each client) processing data cause that would defy the object of writing this server asynchronously.
So what I need to do is have a pool of lets say 5 threads for arguments sake that will process the incoming data of ALL the connected clients... I've never done anything like this and have no idea where to start, is this what thread pools are used for?
If anyone could clarify this or point me in a direction i would be really grateful
Thanks
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Yes. Check out SmartThreadPool 2.0. We're using it at work, and it's absolutely tits. I think the latest version is on CodePlex.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: and it's absolutely tits
I agree, I use it on a different project but not quite like this. I was actually busy brushing up on that article
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
I'll second SmartThreadPool. We use it to hive off our Tcp processing, and it just works.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hey Pete, long time since we've spoken
Pete O'Hanlon wrote: We use it to hive off our Tcp processing, and it just works
So you've done this before?
Here's my PacketReceivedCallback:
private void PacketReceivedCallback(IAsyncResult result)
{
IOClient client = (IOClient)result.AsyncState;
int bytesRead = client.Socket.EndReceive(result);
if (bytesRead != 0)
{
lock (clientLock)
{
StringBuilder sb = new StringBuilder();
if (client.IncompleatePacket.Length > 0)
{
sb = client.IncompleatePacket;
}
foreach (byte CurrentByte in client.ReadBuffer)
{
if (CurrentByte == EmptyByte)
{
continue;
}
if (CurrentByte == PacketTerminator)
{
PacketReceived(client, sb.ToString());
bytesReceived += sb.ToString().Length;
BroadcastPacket(sb.ToString(), client);
sb = new StringBuilder();
client.IncompleatePacket = new StringBuilder();
}
if (CurrentByte != EmptyByte && CurrentByte != PacketTerminator)
{
sb.Append((char)CurrentByte);
}
}
if (sb.Length > 0)
{
client.IncompleatePacket.Append(sb.ToString());
}
}
client.Socket.BeginReceive(client.ReadBuffer, 0, client.ReadBuffer.Length, SocketFlags.None,
new AsyncCallback(PacketReceivedCallback), client);
}
else
{
CloseConnection(client);
}
}
The way I see it is I'll have a collection, possibly a List<string> , in my IOClient class. Instead of trying to split the packets up in the callback I'll call MyStringList.Add(Encoding.ASCII.GetString(client.ReadBuffer,0,bytesRead));
Then my SmartThreadPool will sit and take a piece of data from that list and strip out the individual packets more or less like I'm doing in the above snippet... Is that more or less how its done?
And then would you mind telling me how I make the smart thread pool do this in the most effiecient manner? Like i told JSOP, I've used SmartThreadPool before, but not quite like this...
Thanks bud
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi Harvey,
I haven't done massive TCP/IP on Windows yet, however I looked at your code and have two remarks:
1.
your PacketReceivedCallback() method is asynchronous to everything else in your app, so it is bound to run on a separate thread; earlier experiments like these[^] have convinced me they always run on a Thread from the one and only ThreadPool in .NET
Of course you could modify the scheme in such a way that PacketReceived() rather than processing the packet, just puts it in some queue, then signals its waiter, which could be another Thread, a regular one, a ThreadPool one, or one from any other fancy threadpool you choose. That could be advantageous when your machine has several processors, and I mean more than 2 here. On a 1- or 2-core machine it probably isn't worth the trouble.
2.
Your code is silently converting incoming bytes into chars into strings. That may be fine, however in general TCP/IP transports binary data. It is up to the application layers to decide what that data represents. You probably are aware of all this, but I wanted to say it explicitly just in case.
|
|
|
|
|
Hey Luc
Thanks for your comments...
Luc Pattyn wrote: 2.
Your code is silently converting incoming bytes into chars into strings. That may be fine, however in general TCP/IP transports binary data. It is up to the application layers to decide what that data represents. You probably are aware of all this, but I wanted to say it explicitly just in case.
Yup, I'm just playing around with some proof of concept code before I build the real deal
Me and my stepbrother just discussed this and I think I may have an idea.
The receiving of data happens in the .net ThreadPool as you mentioned and then sends the result back via a callback.
At this point I'll shove the entire piece of data into a collection of some type that resides in my client object. I'll also signal the main processing thread of this event.
This thread will be responsible for checking if a work item for the specific client has been started(in which case it will be ignored cause the thread in progress will process it) or not. If not it will queue the work item in the thread pool.
These work items will then strip the packets from the clients raw data and trigger events in my code that i can handle appropriately.
What you think? do-able?
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
sounds doable.
caveat:
Harvey Saayman wrote: I'll shove the entire piece of data into a collection of some type
that collection will be operated upon by at least two threads (the ThreadPool thread as the only producer, and your nre new thread as the only consumer), so it will need thread-safety precautions, e.g. a Lock. So in the end any of the client threads could potentially block the PacketReceivedCallback thread.
BTW: There also is a delicate way of doing this without a lock, but it is rather hard to get it absolutely safe. You shouldn't even try it before you really need to get rid of all locks.
ADDED:
The official ThreadPool has a particular behavior in that it manages how many threads it is going to use for a particular set of "jobs" (i.e. QueueUserWorkItem() calls). It will dynamically alter the number of threads, but only at a limited pace, something like "no more than 1 extra thread per half second". Which really means work items may get a long delay before they start. That might upset your clever threading scheme and make it look like pretty slow (and even worse than a simple non-threaded approach) at first. One way around it is not to use the ThreadPool, i.e. using real explicit Threads.
BTW: I haven't seen it documented, however I have a test app to prove it; no article yet (that is planned for next year).
modified on Friday, December 18, 2009 2:03 PM
|
|
|
|
|
Thanks bud
Yea, I realize that I'd have to use lock on the said raw data collection... I think I really need to keep the locking to a minimum though. Like when a worker thread from the data processing pool gets a new piece of data, only lock while making a copy to work with and then remove it from the raw data collection so that I dont hold it up so long and the data receiving thread sits and waits anyway...
I was actually reading up on lock and Monitor today, i was so frustrated with this problem i found one mother of an article on threading that explained a whole lot I wasn't even aware of.
I cant wait to try this out, I really hope it works. When I do get it to work I'll be writing an article myself cause I haven't seen any high load .Net TCP server code on the web.
Thanks once again
My girlfriend says in the background: Oh my gosh you guys should learn when to switch off
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:16am.
|
|
|
|
|
Thank you for your reply!
I also know BitConverter class.Please read my post again, convert length to bytes but then b0, b1 have values making (b0<<8) + b1 having the same vr's value before.
That's what I get to.
|
|
|
|
|
Warning: untested
b0 = (byte)length;
b1 = (byte)(length >> 8);
b2 = (byte)(length >> 16);
b3 = (byte)(length >> 24);
|
|
|
|
|
I've made a picturebox where I have a runtime code in. There i open a other Picturebox, but that picturebox I run runtime from the Design Picturebox is under the design picturebox and must be at the top. Hope somebody can help.
Dennis,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace KVzoekscherm
{
public partial class runtimeobject : Form
{
Button button1;
Button button2;
Bitmap image1;
PictureBox pictureBox1;
public runtimeobject()
{
InitializeComponent();
}
private void pbMaak_Click(object sender, EventArgs e)
{
pictureBox1 = new PictureBox();
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.BorderStyle = BorderStyle.None;
pictureBox1.ClientSize = new Size(15, 15);
pictureBox1.Location = new System.Drawing.Point(50, 50);
pictureBox1.Cursor = Cursors.Hand;
pictureBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
pictureBox1.TabIndex = 28;
image1 = new Bitmap(Properties.Resources.edit_gray);
pictureBox1.Image = (Image)image1;
pictureBox1.Click += new EventHandler(editclick);
pictureBox1.MouseLeave += new EventHandler(editleave);
pictureBox1.MouseEnter += new EventHandler(editenter);
this.Controls.Add(pictureBox1);
}
private void editenter(object sender, EventArgs e)
{
image1 = new Bitmap(Properties.Resources.edit_color);
pictureBox1.Image = (Image)image1;
}
private void editleave(object sender, EventArgs e)
{
image1 = new Bitmap(Properties.Resources.edit_gray);
pictureBox1.Image = (Image)image1;
}
private void editclick(object sender, EventArgs e)
{
MessageBox.Show("Clicked");
}
private void runtimeobject_Load(object sender, EventArgs e)
{
}
private void pbMaak_Click_1(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Use this to move control to the back
pictureBox1.SendToBack();
Edit: I suggest you use Name property. If you intended to use Controls to search through controls. It will be easier to get the desired control.
pictureBox1.Name = "pictureBox1";
|
|
|
|
|
But:
pictureBox1.SendToBack();
I will need to send pictureBox1 to the front :P
That option doesn't Exist.
SendToFront 
|
|
|
|
|
|
 II've used this code now all is working BUT!:
Here is is coming:
If i mouseenter and mouseleave it now it is changing the image and if i disable the Bring toFront it is working?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace KVzoekscherm
{
public partial class runtimeobject : Form
{
Button button1;
Button button2;
Bitmap image1;
PictureBox pictureBox1;
public runtimeobject()
{
InitializeComponent();
}
private void pbMaak_Click(object sender, EventArgs e)
{
pictureBox1 = new PictureBox();
pictureBox1.Name = "pictureBox1";
pictureBox1.BringToFront();
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.BorderStyle = BorderStyle.None;
pictureBox1.ClientSize = new Size(15, 15);
pictureBox1.Location = new System.Drawing.Point(50, 50);
pictureBox1.Cursor = Cursors.Hand;
pictureBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
pictureBox1.TabIndex = 28;
image1 = new Bitmap(Properties.Resources.edit_gray);
pictureBox1.Image = (Image)image1;
pictureBox1.Click += new EventHandler(editclick);
pictureBox1.MouseLeave += new EventHandler(editleave);
pictureBox1.MouseEnter += new EventHandler(editenter);
this.Controls.Add(pictureBox1);
}
private void editenter(object sender, EventArgs e)
{
image1 = new Bitmap(Properties.Resources.edit_color);
pictureBox1.Image = (Image)image1;
}
private void editleave(object sender, EventArgs e)
{
image1 = new Bitmap(Properties.Resources.edit_gray);
pictureBox1.Image = (Image)image1;
}
private void editclick(object sender, EventArgs e)
{
MessageBox.Show("Clicked");
}
private void runtimeobject_Load(object sender, EventArgs e)
{
}
private void pbMaak_Click_1(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
If there is control on top of yours, it should affect Mouseenter and MouseLeave events, but I am starting with a job, so I Cant help you now and test it
|
|
|
|
|
Yes im trying some things do will say when it is owkring here. Now waiting for somebody else his help.
Thanks!
|
|
|
|
|
|
Hi.
I want to implement the following scenario :
i have a crawler exe that crawls a site given a url , the url is in an xml file that the crawler reads.
now, i want to be able to have an xml file that have a javascript function that gets the current page that was downloaded in a string from the crawler , and in that function i want to manipulate the page string and return a string to the crawler.
is it possible?
|
|
|
|
|