|
Very good question - it caused me to wonder too!
Basically, when the asynchronous BeginReceive is called, you pass in a state object (which is the "state" instance of the UdpState class I knocked up). This is then received in the callback as the IAsyncResult's AsyncState property. Those two lines basically cast out the udpClient and endPoint contained in the AsyncState so that they can be used.
I'm still trying to figure it out, but I guess you could simply refer to the class level udpClient adn IPEndPoint variables here (the MSDN example didn't have these declared...), but given that what's going on here is asynchronous in nature, it's possible that those class variables could change between the async callback being called and any work actually being processed leading to very subtle bugs.
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
Thank you so much for your help.
I finally understand and have gotten the Async sockets to work. However I am having a rather small problem, and since I am new to C#, I cannot figure out the solution.
basically, I have a windows form with a few labels on it that need to be updated with each packet. my problem is in the permissions for accessing and setting these variables. Since the labels are properties in a windows form and the UDP listener is int the program.cs, I have no way of accessing these values from ReceiveCallback to update the form.
Ideally, with every loop through the callback function I would want to update label1 & label2 in my form (with already parsed bytes from the stream). Yet I cannot access label1 or label2 from the ReceiveCallback function where I am doing the byte stream parsing.... would you (or anyone!) by any chance have some insight on this?
thanks,
Joe
I am who I am because of who everyone around me is.
|
|
|
|
|
Well there are a number of possible options, but I think using events might be the best solution for you here.
Basically you'd setup up an Event in your Packet Listener class which fires every time a packet is received. You could then have your form listen to those events, and update accordingly, taking an an Event Argument from the fired event. You'll definintely have to look at cross threading issues (this is because having two threads update a UI is a bad idea), but this isn't too difficult, and there are some articles on CP which explain how to do this.
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
I have a phare of source:
InitializeComponent();
String []Nhat=Directory.GetDirectories(Directory.GetCurrentDirectory());
String Nht = Nhat[0];
when I debug,no happen,but when I run the progam,a dialogue display and require me to close dialogue,why I don't undersand
|
|
|
|
|
I don't understand.
What should happen?
What actually happens?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
You are making an assumption in the line String Nht = Nhat[0] that you actually have an entry. Before you do this, you need to make sure that Nhat actually has entries in it.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
but why when I debug,Nhat[] have contained data( data is a String)
|
|
|
|
|
Because you are using GetCurrentDirectory. Here's a hint - pop up a message box to say what GetCurrentDirectory contains in the release version.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Whatever happens, don't give us any details.
If a dialog box tells you something, don't tell us.
If an Exception fires, don't reveal its message.
If you did, we might be able to help you; that can not be what you want...
|
|
|
|
|
I know its a silly ques.
I've got treeview control which holds different class names.
In normal ways what we do is.
Ayclass cls= new AnyClass();
now the AnyClass's name is stored in a variable. how to instantiate a class.
here's the failed code.
string varClass= treeview1.node.ToString();
varclass d= new varClass();
Hope I make myself clarify.
|
|
|
|
|
Normally you don't do this at all. It's possible using reflection, but having to use reflection is usually an indication that you are doing something backwards.
What is it that you are trying to accomplish, really? You should ask for a solution for that, instead of asking about the way that you think that it's solved.
---
single minded; short sighted; long gone;
|
|
|
|
|
If you are sure that's the way to go (see post from Guffa) then this is how it's working:
object d = Activator.CreateInstance(Type.GetType(typeName));
see help on CreateInstance for further information.
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
here's what I want.
here's chart reports in treeview control for end user to display.
Sales_Monthwise
Sales_Citywise
sales_PartyWise
when a user clicks Sales_Monthwise I want open Charting Class with the same name.
one possible way is:
if (treeview.node.text == "Sales_MonthWise) {
Sales_Monthwise sm= new Sales_Monthwise();
sm.Show();
}
bcoz there are so many classes I don't want to insert logic for every class.
|
|
|
|
|
|
Hi all,
Can i get some notes or some article link on .NET Threading.
Thank You,
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
I'll let you in on a secret (I know its a secret because it seems theres a lot of people who don't use it before asking here), theres a wonderful site called google[^].
|
|
|
|
|
|
Now you ruined it! That was supposed to be THE secret!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
I'll let you in on the biggest secret of all (I know its a big secret because
it seems only few people are aware of it): there is a Search box on top of almost
every page on CodeProject.
Don't use it; if you do, you may run out of simple questions to ask us.
|
|
|
|
|
i have a main form which contains 5 tab pages in each tab page i have a list view. now if i open another form from main form using childform.showdialog() and then i close the child form then the main form flickers, i dont know why? but if i open the same child form from main form using childfrom.show() then close it the main form doest flicker but the show method allows multiple instance of child form which is not so in showdialog(). Now what should i do in order to open single instance of child form and not flicker the main form when the child form closes.
thank you
|
|
|
|
|
I believe there is a property "DoubleBuffering" or something in the forms properties.
Set it to true. Maybe that helps.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
Hi There
I need help to get started making a simple addin for Word. I need to add a command in menu that appears when I right clicks, so I can execute some of my own code.
I'm tryin to do so using VS2005 (C#) and VSTO2005. But I can't find any samples that leads my in the correct direction.
Can anyone helt me, please?
__________________
John Reinhold - DK
|
|
|
|
|
use ContextMenu. assign some text as menu in it.Now there is one property in form class.so assign Context menu name in its Context menu property.
u r done!!
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|